common

package module
v0.0.0-...-7d786f5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const (
	BogusIdentifier = "123412341234123456"
)

Variables

This section is empty.

Functions

func GenericErr

func GenericErr(status int, err error) error

GenericErr returns an error appropriate to the given HTTP status (or actual error, if given).

func GenericErrFromResponse

func GenericErrFromResponse(resp *http.Response, err error) error

func Req

func Req(httpClient *http.Client, timeoutHandler TimeoutHandler, mode string, uri string, data any, queryParams url.Values, headers map[string]string, response bool) (string, int, error)

Stripped down-ish version of rough http request function used in most of the API clients.

Types

type Config

type Config struct {
	Sections []Section `json:"sections" yaml:"sections"`
	Groups   []Group   `json:"groups" yaml:"groups"`
	// Optional order, which can interleave sections and groups.
	// If unset, falls back to sections in order, then groups in order.
	Order []Member `json:"order,omitempty" yaml:"order,omitempty"`
}

type ConfigurableTransport

type ConfigurableTransport interface {
	// SetTransport sets the http.Transport to use for requests. Can be used to set a proxy.
	SetTransport(t *http.Transport)
}

type ContactPreferences

type ContactPreferences struct {
	Email, Discord, Telegram, Matrix *bool
}

ContactPreferences holds whether or not a user should be contacted through each of the available methods. If nil, leave setting alone.

type ErrForbidden

type ErrForbidden struct{}

func (ErrForbidden) Error

func (err ErrForbidden) Error() string

type ErrNotFound

type ErrNotFound error

most 404 errors are from UserNotFound, so this generic error doesn't really need any detail.

var (
	NotFound ErrNotFound = errors.New(lm.NotFound)
)

type ErrUnauthorized

type ErrUnauthorized struct{}

func (ErrUnauthorized) Error

func (err ErrUnauthorized) Error() string

type ErrUnknown

type ErrUnknown struct {
	// contains filtered or unexported fields
}

func (ErrUnknown) Error

func (err ErrUnknown) Error() string

type Group

type Group struct {
	Group       string   `json:"group" yaml:"group" example:"messaging_providers"`
	Name        string   `json:"name" yaml:"name" example:"Messaging Providers"`
	Description string   `json:"description" yaml:"description" example:"Options for setting up messaging providers."`
	Members     []Member `json:"members" yaml:"members"`
}

type Member

type Member struct {
	Group   string `json:"group,omitempty", yaml:"group,omitempty"`
	Section string `json:"section,omitempty", yaml:"section,omitempty"`
}

Member is a member of a group, and can either reference a Section or another Group, hence the two fields.

type MustAuthenticateOptions

type MustAuthenticateOptions struct {
	RetryCount  int           // Number of Retries before failure.
	RetryGap    time.Duration // Duration to wait between tries.
	LogFailures bool          // Whether or not to print failures to the log.
	Counter     int           // The current retry count.
}

MustAuthenticateOptions is used to control the behaviour of the MustAuthenticate-like methods.

type Option

type Option [2]string

type Section

type Section struct {
	Section  string      `json:"section" yaml:"section" example:"my_section"`
	Meta     SectionMeta `json:"meta" yaml:"meta"`
	Settings []Setting   `json:"settings" yaml:"settings"`
}

type SectionMeta

type SectionMeta struct {
	Name         string   `json:"name" yaml:"name" example:"My Section"` // friendly name of the section
	Description  string   `json:"description" yaml:"description"`
	Advanced     bool     `json:"advanced,omitempty" yaml:"advanced,omitempty"`
	Disabled     bool     `json:"disabled,omitempty" yaml:"disabled,omitempty"`
	DependsTrue  string   `json:"depends_true,omitempty" yaml:"depends_true,omitempty"`
	DependsFalse string   `json:"depends_false,omitempty" yaml:"depends_false,omitempty"`
	WikiLink     string   `json:"wiki_link,omitempty" yaml:"wiki_link,omitempty"`
	Aliases      []string `json:"aliases,omitempty" yaml:"aliases,omitempty"`
}

type Setting

type Setting struct {
	Setting         string      `json:"setting" yaml:"setting" example:"my_setting"`
	Name            string      `json:"name" yaml:"name" example:"My Setting"`
	Description     string      `json:"description" yaml:"description"`
	Required        bool        `json:"required" yaml:"required"`
	RequiresRestart bool        `json:"requires_restart" yaml:"requires_restart"`
	Advanced        bool        `json:"advanced,omitempty" yaml:"advanced,omitempty"`
	Type            SettingType `json:"type" yaml:"type"` // Type (string, number, bool, etc.)
	Value           any         `json:"value" yaml:"value"`
	Options         []Option    `json:"options,omitempty" yaml:"options,omitempty"`
	DependsTrue     string      `json:"depends_true,omitempty" yaml:"depends_true,omitempty"`   // If specified, this field is enabled when the specified bool setting is enabled.
	DependsFalse    string      `json:"depends_false,omitempty" yaml:"depends_false,omitempty"` // If specified, opposite behaviour of DependsTrue.
	Style           string      `json:"style,omitempty" yaml:"style,omitempty"`
	Deprecated      bool        `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	WikiLink        string      `json:"wiki_link,omitempty" yaml:"wiki_link,omitempty"`
	Aliases         []string    `json:"aliases,omitempty" yaml:"aliases,omitempty"`
}

type SettingType

type SettingType string
var (
	BoolType     SettingType = "bool"
	SelectType   SettingType = "select"
	TextType     SettingType = "text"
	PasswordType SettingType = "password"
	NumberType   SettingType = "number"
	NoteType     SettingType = "note"
	EmailType    SettingType = "email"
	ListType     SettingType = "list"
)

type TimeoutHandler

type TimeoutHandler func()

TimeoutHandler recovers from an http timeout or panic.

func NewTimeoutHandler

func NewTimeoutHandler(name, addr string, noFail bool) TimeoutHandler

NewTimeoutHandler returns a new Timeout handler.

Jump to

Keyboard shortcuts

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