lib

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RecordNotFound             = Error{Code: 1, Type: "RecordNotFound", Message: "The database record was not found"}
	UserNotFound               = Error{Code: 10, Status: http.StatusNotFound, Type: "UserNotFound", Message: "user does not exist"}
	UserAlreadyExists          = Error{Code: 11, Type: "UserAlreadyExists", Message: "user already exists"}
	UsernameAlreadyTaken       = Error{Code: 12, Type: "UsernameAlreadyTaken", Message: "username already taken"}
	UserNotActivated           = Error{Code: 100, Type: "UserNotActivated", Message: "activation required"}
	InvalidActivateToken       = Error{Code: 101, Type: "InvalidActivateToken", Message: "invalid token"}
	InvalidResetToken          = Error{Code: 110, Type: "InvalidResetToken", Message: "invalid token"}
	PasswordTooShort           = Error{Code: 200, Type: "PasswordTooShort", Message: "password too short"}
	PasswordNeedsUpperChar     = Error{Code: 201, Type: "PasswordNeedsUpperChar", Message: "password needs upper char"}
	PasswordNeedsLowerChar     = Error{Code: 202, Type: "PasswordNeedsLowerChar", Message: "password needs lower char"}
	PasswordNeedsDigit         = Error{Code: 203, Type: "PasswordNeedsDigit", Message: "password needs digit"}
	InvalidPassword            = Error{Code: 220, Type: "InvalidPassword", Message: "invalid password"}
	InvalidEmailAddress        = Error{Code: 221, Type: "InvalidEmailAddress", Message: "email address is not valid"}
	AccessTokenLimit           = Error{Code: 230, Type: "AccessTokenLimit", Message: "device login limit exceeded"}
	ConsumerNotFound           = Error{Code: 300, Type: "ConsumerNotFound", Message: "consumer does not exist."}
	NamespaceNotFound          = Error{Code: 400, Type: "NamespaceNotFound", Message: "namespace does not exist."}
	OrganizationNotFound       = Error{Code: 500, Type: "OrganizationNotFound", Message: "organization does not exist"}
	OrganizationAlreadyExists  = Error{Code: 501, Type: "OrganizationAlreadyExists", Message: "organization already exists"}
	ProjectNotFound            = Error{Code: 510, Type: "ProjectNotFound", Message: "project does not exist"}
	ProjectAlreadyExists       = Error{Code: 512, Type: "ProjectAlreadyExists", Message: "project already exists"}
	InviteTokenNotFound        = Error{Code: 600, Type: "InviteTokenNotFound", Message: "invite token does not exist"}
	PolicyNotFound             = Error{Code: 700, Type: "PolicyNotFound", Message: "policy does not exist"}
	RequiresAdminPolicy        = Error{Code: 700, Type: "RequiresAdminPolicy", Message: "Administrative policy does not exist"}
	RequestTokenNotFound       = Error{Code: 0, Type: "RequestTokenNotFound", Message: "request token does not exist"}
	AccessTokenNotFound        = Error{Code: 231, Status: http.StatusUnauthorized, Type: "AccessTokenNotFound", Message: "access token does not exist"}
	InputValidationError       = Error{Code: 0, Status: http.StatusBadRequest, Type: "InputValidationError"}
	CaptchaInvalid             = Error{Code: 20000, Type: "CaptchaInvalid"}
	AddressRequired            = Error{Code: 30000, Type: "AddressRequired"}
	VoucherNotFound            = Error{Code: 31001, Type: "VoucherNotFound"}
	VoucherRedeemed            = Error{Code: 31002, Type: "VoucherRedeemed"}
	VoucherInvalidPublication  = Error{Code: 31003, Type: "VoucherInvalidPublication"}
	SubscriptionHasAccess      = Error{Code: 31004, Type: "SubscriptionHasAccess"}
	OfferNotGiftable           = Error{Code: 31005, Type: "OfferNotGiftable"}
	CampaignNotFound           = Error{Code: 32000, Type: "CampaignNotFound"}
	SubNotFound                = Error{Code: 35000, Type: "SubNotFound"}
	TransNotFound              = Error{Code: 35100, Type: "TransNotFound"}
	TransProcessed             = Error{Code: 35110, Type: "TransProcessed"}
	PaymentAlreadyCaptured     = Error{Code: 35200, Type: "PaymentAlreadyCaptured"}
	PaymentMethodUnsupported   = Error{Code: 36200, Type: "PaymentMethodUnsupported"}
	AlreadySubscribedToPackage = Error{Code: 35001, Type: "AlreadySubscribedToPackage"}
)
View Source
var Config struct {
	// Enables verbose logging
	Debug          bool
	TestMode       bool
	AuthCookieName string
}

Functions

func CreateSha1Hash

func CreateSha1Hash(str string) string

func ErrSuffix

func ErrSuffix(in string) string

func GetSecureString

func GetSecureString() string

Generates a SHA512 hash from a UUID. This string can be used as a token for authentication, etc.

func GetTempPassword

func GetTempPassword(email string, salt string) string

func GetUUID

func GetUUID() string

func HashPassword

func HashPassword(pwd string, salt string) string

func RegisterMetadataEndpoint

func RegisterMetadataEndpoint(s Service)

func RegisterOpenApiEndpoint

func RegisterOpenApiEndpoint(s Service)

func RegisterService

func RegisterService[T IService](r IRequestContext, service T) T

Register services or middlware for lifetime events

func RequestHandler

func RequestHandler[I, O any, C IRequestContext](ctx *RequestContext, in *I, handler HandleFunc[I, O, C]) O

func ToSnakeCase

func ToSnakeCase(str string) string

func VerifyPassword

func VerifyPassword(pwd string) error

Types

type ApiDoc

type ApiDoc struct {
	Service Service
	// contains filtered or unexported fields
}

func NewApiDocumentation

func NewApiDocumentation(service Service) ApiDoc

type Error

type Error struct {
	Code    int      `json:"code"`
	Type    string   `json:"type"`
	Message string   `json:"error"`
	Errors  []string `json:"-"`
	Link    string   `json:"-"` // Link to the Docs
	Status  int      `json:"-"`
}

func (Error) Error

func (err Error) Error() string

type HandleFunc

type HandleFunc[I, O any, C IRequestContext] func(context C, in *I) O

func Base

func Base[I, O any, C IRequestContext](r Route, handler HandleFunc[I, O, C]) HandleFunc[I, O, C]

Binds a route to a handler function

type IOTime

type IOTime struct {
	time.Time
}

func (IOTime) MarshalJSON

func (t IOTime) MarshalJSON() ([]byte, error)

func (*IOTime) UnmarshalJSON

func (t *IOTime) UnmarshalJSON(data []byte) error

type IRequestContext

type IRequestContext interface {
	Init(r RequestContext)
	AddService(svc IService)
	OnAuthentication()
	OnException()
	OnSuccess()
	Dispose()
}

type IService

type IService interface {
	Dispose()
	OnSuccess()
	OnException()
	OnAuthentication()
}

type Inner

type Inner interface {
	Name() string
}

type Mail

type Mail struct {
	From             Recipient
	To               Recipient
	Subject          string
	PlainTextContent string
	HtmlContent      string
}

func (Mail) Send

func (m Mail) Send()

type MetaArgument

type MetaArgument struct {
	Type        string `json:"type"`
	Format      string `json:"format"`
	Description string `json:"desc"`
	Default     string `json:"default"`
	Required    bool   `json:"required"`
}

type MetaRoute

type MetaRoute struct {
	Url        string                    `json:"url"`
	Method     string                    `json:"method"`
	Desc       string                    `json:"desc"`
	Permission string                    `json:"permission"`
	Args       map[string](MetaArgument) `json:"args"`
}

type Model

type Model struct {
	Id        string
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (*Model) SetId

func (m *Model) SetId(id string)

type Modelable

type Modelable interface {
	SetId(id int)
}

type Option

type Option[T any] struct {
	Value T
	// Returns true if the value was set
	HasValue bool `json:"-"`
}

func NewOption

func NewOption[T any](value T) Option[T]

func (Option[T]) AlternateType

func (d Option[T]) AlternateType() any

TODO: rename to GetUnderlyingType/GetAPIType or something

func (*Option[T]) If

func (d *Option[T]) If(fn func(T))

Call function if value is set.

func (Option[T]) MarshalJSON

func (d Option[T]) MarshalJSON() ([]byte, error)

func (*Option[T]) Or

func (d *Option[T]) Or(v T) T

Return current value if set, or else return specified value.

func (*Option[T]) Set

func (d *Option[T]) Set(v T)

func (*Option[T]) UnmarshalJSON

func (d *Option[T]) UnmarshalJSON(data []byte) error

type Recipient

type Recipient struct {
	Name  string
	Email string
}

type RequestContext

type RequestContext struct {
	Route   *Route
	Service Service

	Request     *http.Request
	Writer      http.ResponseWriter
	AccessToken string
	// contains filtered or unexported fields
}

func (*RequestContext) AddService

func (r *RequestContext) AddService(svc IService)

func (*RequestContext) Dispose

func (r *RequestContext) Dispose()

func (*RequestContext) GetAccessToken

func (r *RequestContext) GetAccessToken() string

func (*RequestContext) Init

func (r *RequestContext) Init(ctx RequestContext)

func (*RequestContext) OnAuthentication

func (r *RequestContext) OnAuthentication()

func (*RequestContext) OnException

func (r *RequestContext) OnException()

func (*RequestContext) OnSuccess

func (r *RequestContext) OnSuccess()

func (*RequestContext) Success

func (r *RequestContext) Success() Success

type Route

type Route struct {
	Path        string
	Description string
	Permission  string
	Category    string
	Service     Service // TODO: fill this
	Summary     string
	OpId        string // The operation ID of the endpoint
	ServicePath string
	FilePath    string
	Errors      []Error // Errors returned by route
	Input       any
	Output      any
	InputSchema string
	Handle      func(r *RequestContext, in any) any
}

type Service

type Service struct {
	Name        string
	Version     string
	Prefix      string
	Path        string
	SnakifyIO   bool
	Overview    []byte
	StaticFiles *embed.FS
}

func (Service) ContainsRoute

func (s Service) ContainsRoute(r *Route) bool

func (Service) GetRoutes

func (s Service) GetRoutes() []*Route

type Success

type Success struct {
	Success bool `json:"success"`
	Message bool `json:"message,omitempty"`
}

type Union

type Union struct {
	Inner
}

func (Union) InlineJSONSchema

func (Union) InlineJSONSchema()

func (Union) MarshalJSON

func (u Union) MarshalJSON() ([]byte, error)

func (*Union) UnmarshalJSON__

func (u *Union) UnmarshalJSON__(data []byte, widgets []any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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