api

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EndpointApiAccessKeys         = "/api/admin-access-keys"
	EndpointApiAdminUsers         = "/api/admin-users"
	EndpointApiLogin              = "/api/login"
	EndpointApiRegister           = "/api/register"
	EndpointApiActivate           = "/api/activate"
	EndpointCaptchaMultiple       = "/api/captcha/"
	EndpointCaptchaSingle         = "/api/captcha"
	EndpointAppInfo               = "/api/app-info"
	EndpointApiPerformance        = "/api/performance"
	EndpointApiChangePassword     = "/api/change-password"
	EndpointApiRequestEmailChange = "/api/request-email-change"
	EndpointApiConfirmEmailChange = "/api/confirm-email-change"

	EndpointApiCryptoPaymentConfig        = "/api/crypto-payment/config"
	EndpointApiCryptoPaymentCreateAddress = "/api/crypto-payment/create-address"
	EndpointApiCryptoPaymentAccount       = "/api/crypto-payment/account"
	EndpointApiAdminCryptoPaymentAccount  = "/api/admin-crypto-payment/account"

	EndpointSwagger = "/swagger/"
	EndpointRoot    = "/"

	EndpointFrontendLogin = "/#/login"
)

Constants for endpoint namings

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware(next http.Handler) http.Handler

CORSMiddleware enables CORS for the handler

func NewAPIEngine

func NewAPIEngine(address string, generalHandler http.Handler) (*apiEngine, error)

NewAPIEngine creates and opens a new API engine

func NewAccessKeysHandler

func NewAccessKeysHandler(keyAccessProvider KeyAccessProvider, auth Authenticator) (*accessKeysHandler, error)

NewAccessKeysHandler creates a new AccessKeysHandler

func NewCaptchaHandler

func NewCaptchaHandler(handler CaptchaHandler) (*captchaHandler, error)

NewCaptchaHandler creates a new captcha handler

func NewCryptoPaymentHandler

func NewCryptoPaymentHandler(
	client CryptoPaymentClient,
	storage KeyAccessProvider,
	auth Authenticator,
	mutexes MutexHandler,
) (*cryptoPaymentHandler, error)

NewCryptoPaymentHandler creates a new cryptoPaymentHandler instance

func NewGatewayTester

func NewGatewayTester() *gatewayTester

NewGatewayTester returns an instance of type gatewayTester

func NewJWTAuthenticator

func NewJWTAuthenticator(key string) *jwtAuthenticator

NewJWTAuthenticator creates a new jwtAuthenticator instance

func NewLoginHandler

func NewLoginHandler(provider KeyAccessProvider, auth Authenticator) (*loginHandler, error)

NewLoginHandler creates a new login handler

func NewPerformanceHandler

func NewPerformanceHandler(keyAccessProvider KeyAccessProvider, auth Authenticator) (*performanceHandler, error)

NewPerformanceHandler creates a new performanceHandler instance

func NewRegistrationHandler

func NewRegistrationHandler(
	keyAccessProvider KeyAccessProvider,
	emailSender EmailSender,
	appDomainsConfig config.AppDomainsConfig,
	captchaHandler CaptchaHandler,
	htmlTemplate string,
) (*registrationHandler, error)

NewRegistrationHandler creates a new registrationHandler instance

func NewUserCredentialsHandler

func NewUserCredentialsHandler(
	keyAccessProvider KeyAccessProvider,
	emailSender EmailSender,
	appDomainsConfig config.AppDomainsConfig,
	htmlTemplate string,
	auth Authenticator,
) (*userCredentialsHandler, error)

NewUserCredentialsHandler creates a new userCredentialsHandler instance

func NewUsersHandler

func NewUsersHandler(keyAccessProvider KeyAccessProvider, auth Authenticator) (*usersHandler, error)

NewUsersHandler creates a new usersHandler instance

Types

type Authenticator

type Authenticator interface {
	GenerateToken(username string, isAdmin bool) (string, error)
	CheckAuth(r *http.Request) (*common.Claims, error)
	IsInterfaceNil() bool
}

Authenticator defines the behavior for authentication

type CaptchaHandler

type CaptchaHandler interface {
	VerifyString(id string, digits string) bool
	NewCaptcha() string
	Reload(id string)
	WriteNoError(w io.Writer, id string)
	IsInterfaceNil() bool
}

CaptchaHandler defines the operations supported by a component able to generate & test captchas

type CaptchaResponse

type CaptchaResponse struct {
	CaptchaId string `json:"captchaId"`
}

CaptchaResponse holds the captcha ID

type CryptoPaymentClient

type CryptoPaymentClient interface {
	GetConfig() (*common.CryptoPaymentConfig, error)
	CreateAddress() (*common.CreateAddressResponse, error)
	GetAccount(paymentID uint64) (*common.AccountInfo, error)
	IsInterfaceNil() bool
}

CryptoPaymentClient handles communication with the crypto-payment service

type EmailSender

type EmailSender interface {
	SendEmail(to string, subject string, body any, htmlTemplate string) error
	IsInterfaceNil() bool
}

EmailSender defines the operations supported by a component able to send emails

type KeyAccessProvider

type KeyAccessProvider interface {
	AddUser(username string, password string, isAdmin bool, maxRequests uint64, isPremium bool, isActive bool, activationToken string) error
	ActivateUser(token string) error
	GetAllUsers() (map[string]common.UsersDetails, error)
	IsKeyAllowed(key string) (string, common.AccountType, error)
	CheckUserCredentials(username string, password string) (*common.UsersDetails, error)
	GetAllKeys(username string) (map[string]common.AccessKeyDetails, error)
	AddKey(username string, key string) error
	RemoveKey(username string, key string) error
	RemoveUser(username string) error
	UpdateUser(username string, password string, isAdmin bool, maxRequests uint64, isPremium bool) error
	GetUser(username string) (*common.UsersDetails, error)
	GetPerformanceMetrics() (map[string]uint64, error)
	UpdatePassword(username string, password string) error
	RequestEmailChange(username string, newEmail string, token string) error
	ConfirmEmailChange(token string) (string, error)
	SetCryptoPaymentID(username string, paymentID uint64) error
	Close() error
	IsInterfaceNil() bool
}

KeyAccessProvider can decide if a provided key has or not query access

type MutexHandler

type MutexHandler interface {
	TryLock(username string) error
	Unlock(username string)
	IsInterfaceNil() bool
}

MutexHandler defines the operations supported by a component able to lock/unlock users

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL