{"modulePath":"github.com/COMTOP1/api","version":"v0.0.0-20261013160217-6eca15d21c26","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package utils\n\n## Variables\n\n```go\nvar (\n\tErrNoToken      = errors.New(\"token not found\")\n\tErrInvalidToken = errors.New(\"invalid token\")\n)\n```\n\n## Functions\n\n```go\nfunc NewDB(config DatabaseConfig) (bucket *gocb.Bucket, err error)\n```\nNewDB Initialises the connection to the database\n\n## Types\n\n```go\ntype AFCAccessClaims struct {\n\tId   uint64 `json:\"id\"`\n\tRole string `json:\"role\"`\n\tjwt.StandardClaims\n}\n```\n\n```go\ntype AccessClaims struct {\n\tUserID      int      `json:\"id\"`\n\tRole        string   `json:\"role\"`\n\tPermissions []string `json:\"perms\"`\n\tjwt.StandardClaims\n}\n```\nAccessClaims represents an identifiable JWT\n\n```go\ntype Accesser struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewAccesser(conf AccesserConfig) *Accesser\n```\nNewAccesser allows the validation of JWT tokens both as headers and as cookies\n\n```go\nfunc (a *Accesser) AFCAdminMiddleware(next echo.HandlerFunc) echo.HandlerFunc\n```\n\n```go\nfunc (a *Accesser) AFCAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc\n```\nAFCAuthMiddleware checks a HTTP request for a valid token either in the header or cookie\n\n```go\nfunc (a *Accesser) AdminAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc\n```\nAdminAuthMiddleware checks a HTTP request for a valid token either in the header or cookie\n\n```go\nfunc (a *Accesser) AdminInitAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc\n```\nAdminInitAuthMiddleware checks a HTTP request for a valid token either in the header or cookie\n\n```go\nfunc (a *Accesser) AuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc\n```\nAuthMiddleware checks a HTTP request for a valid token either in the header or cookie\n\n```go\nfunc (a *Accesser) FindAdminToken(r *http.Request) bool\n```\nFindAdminToken will return the claims from an AFC access token JWT\n\nFirst will check the Authorization header, if unset will check the access cookie\n\n```go\nfunc (a *Accesser) GetAFCToken(r *http.Request) (*AFCAccessClaims, error)\n```\nGetAFCToken will return the claims from an AFC access token JWT\n\nFirst will check the Authorization header, if unset will check the access cookie\n\n```go\nfunc (a *Accesser) GetAdminToken(r *http.Request) (*jwt.Token, error)\n```\nGetAdminToken will return the claims from an admin access token JWT\n\nFirst will check the Authorization header, if unset will check the access cookie\n\n```go\nfunc (a *Accesser) GetAdminTokenKIDAndClaims(r *http.Request) (string, *jwt.StandardClaims, error)\n```\nGetAdminTokenKIDAndClaims will return the claims from an admin access token JWT\n\nFirst will check the Authorization header, if unset will check the access cookie\n\n```go\nfunc (a *Accesser) GetToken(r *http.Request) (*AccessClaims, error)\n```\nGetToken will return the claims from an access token JWT\n\nFirst will check the Authorization header, if unset will check the access cookie\n\n```go\nfunc (a *Accesser) NilMiddleware(next echo.HandlerFunc) echo.HandlerFunc\n```\nNilMiddleware checks a HTTP request for a valid token either in the header or cookie\n\n```go\ntype AccesserConfig struct {\n\tAccessCookieName string\n\tSigningKey       []byte\n\tDomainName       string\n\tAdmin            Admin\n}\n```\n\n```go\ntype Admin struct {\n\tAdminAccessCookieName, Key0, Key1, Key2, Key3, TOTP string\n}\n```\n\n```go\ntype AdminRequest struct {\n\tKey0     string `json:\"key_0\"`\n\tKey1     string `json:\"key_1\"`\n\tKey2     string `json:\"key_2\"`\n\tKey3     string `json:\"key_3\"`\n\tTOTPCode string `json:\"totp_code\"`\n}\n```\n\n```go\ntype AdminResponse struct {\n\tJWTToken string `json:\"jwt_token\"`\n}\n```\n\n```go\ntype Config struct {\n\tHost     string\n\tPort     int\n\tUsername string\n\tPassword string\n\tDefaults Defaults\n}\n```\nConfig represents a configuration to connect to an SMTP server\n\n```go\ntype DatabaseConfig struct {\n\tHost     string\n\tSSLMode  string\n\tBucket   string\n\tUsername string\n\tPassword string\n}\n```\nDatabaseConfig represents a configuration to connect to an SQL database\n\n```go\ntype Defaults struct {\n\tDefaultTo   string\n\tDefaultCC   []string\n\tDefaultBCC  []string\n\tDefaultFrom string\n}\n```\nDefaults is the default values for the mailer if none are explicitly mentioned\n\n```go\ntype Error struct {\n\tError string `json:\"error\"`\n}\n```\n\n```go\ntype Mail struct {\n\tSubject string\n\tTo      string\n\tCc      []string\n\tBcc     []string\n\tFrom    string\n\tError   error\n\tTpl     *template.Template\n\tTplData interface{}\n}\n```\nMail represents an email to be sent\n\n```go\ntype Mailer struct {\n\t*mail.SMTPClient\n\tDefaults Defaults\n}\n```\nMailer is the struct that is used to send mail, can only be used once connected to mailer\n\n```go\nfunc (m *Mailer) CheckSendable(item Mail) error\n```\nCheckSendable verifies that the email can be sent\n\n```go\nfunc (m *Mailer) SendMail(item Mail) error\n```\nSendMail sends a template email\n\n```go\ntype MailerInit struct {\n\tSMTPServer mail.SMTPServer\n\tDefaults   Defaults\n}\n```\nMailerInit is the config store for the mailer, can be initialised once then connected multiple times\n\n```go\nfunc NewMailer(config Config) *MailerInit\n```\nNewMailer creates a new SMTP client\n\n```go\nfunc (m *MailerInit) ConnectMailer() *Mailer\n```\nConnectMailer connects to the mail server\n\n```go\ntype Permission struct {\n\tName string `json:\"name\"`\n}\n```\nPermission represents the permissions that a user has\n\n","path":"github.com/COMTOP1/api/utils","name":"utils","synopsis":"","isRedistributable":true}
