server

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 30 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSuchUser    = errors.New("no such user")
	ErrNoSuchAddress = errors.New("no such address")
	ErrNoSuchLabel   = errors.New("no such label")
)

Functions

This section is empty.

Types

type AuthCacher

type AuthCacher interface {
	GetAuthInfo(username string) (proton.AuthInfo, bool)
	SetAuthInfo(username string, info proton.AuthInfo)
	GetAuth(username string) (proton.Auth, bool)
	SetAuth(username string, auth proton.Auth)
}

func NewAuthCache

func NewAuthCache() AuthCacher

type Call

type Call struct {
	URL    *url.URL
	Method string
	Status int

	Time     time.Time
	Duration time.Duration

	RequestHeader http.Header
	RequestBody   []byte

	ResponseHeader http.Header
	ResponseBody   []byte
}

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) ([]byte, error)

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option represents a type that can be used to configure the server.

func WithAuthCacher

func WithAuthCacher(cacher AuthCacher) Option

func WithDomain added in v0.2.2

func WithDomain(domain string) Option

withDomain controls the domain of the server.

func WithListener added in v0.4.0

func WithListener(listener net.Listener) Option

WithListener allows you to set the net.Listener to use.

func WithLogger

func WithLogger(logger io.Writer) Option

WithLogger controls where Gin logs to.

func WithProxyOrigin

func WithProxyOrigin(origin string) Option

func WithProxyTransport added in v0.2.2

func WithProxyTransport(transport *http.Transport) Option

func WithRateLimit added in v0.2.2

func WithRateLimit(limit int, window time.Duration) Option

func WithServerConfig added in v0.4.0

func WithServerConfig(cfg *http.Server) Option

WithServerConfig allows you to configure the underlying HTTP server.

func WithTLS

func WithTLS(tls bool) Option

WithTLS controls whether the server should serve over TLS.

type Server

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

func New

func New(opts ...Option) *Server

func (*Server) AddAddressCreatedEvent added in v0.4.0

func (s *Server) AddAddressCreatedEvent(userID, addrID string) error

func (*Server) AddCallWatcher

func (s *Server) AddCallWatcher(fn func(Call), paths ...string)

AddCallWatcher adds a call watcher to the server.

func (*Server) AddLabelCreatedEvent added in v0.4.0

func (s *Server) AddLabelCreatedEvent(userID, labelID string) error

func (*Server) AddMessageCreatedEvent added in v0.4.0

func (s *Server) AddMessageCreatedEvent(userID, messageID string) error

func (*Server) AddStatusHook added in v0.4.0

func (s *Server) AddStatusHook(fn StatusHook)

AddStatusHook adds a status hook to the server.

func (*Server) Close

func (s *Server) Close()

func (*Server) CreateAddress

func (s *Server) CreateAddress(userID, email string, password []byte) (string, error)

func (*Server) CreateAddressKey

func (s *Server) CreateAddressKey(userID, addrID string, password []byte) error

func (*Server) CreateLabel

func (s *Server) CreateLabel(userID, name, parentID string, labelType proton.LabelType) (string, error)

func (*Server) CreateUser

func (s *Server) CreateUser(username string, password []byte) (string, string, error)

CreateUser creates a new server user with the given username and password. A single address will be created for the user, derived from the username and the server's domain.

func (*Server) CreateUserKey

func (s *Server) CreateUserKey(userID string, password []byte) error

func (*Server) GetDomain added in v0.2.2

func (s *Server) GetDomain() string

GetDomain returns the domain of the server (e.g. "proton.local").

func (*Server) GetHostURL

func (s *Server) GetHostURL() string

GetHostURL returns the API root to make calls to.

func (*Server) GetLabels

func (s *Server) GetLabels(userID string) ([]proton.Label, error)

func (*Server) GetProxyURL

func (s *Server) GetProxyURL() string

GetProxyURL returns the API root to make calls to which should be proxied.

func (*Server) GetUserKeyIDs

func (s *Server) GetUserKeyIDs(userID string) ([]string, error)

func (*Server) LabelMessage

func (s *Server) LabelMessage(userID, msgID, labelID string) error

func (*Server) RefreshUser

func (s *Server) RefreshUser(userID string, refresh proton.RefreshFlag) error

func (*Server) RemoveAddress

func (s *Server) RemoveAddress(userID, addrID string) error

func (*Server) RemoveAddressKey

func (s *Server) RemoveAddressKey(userID, addrID, keyID string) error

func (*Server) RemoveUser

func (s *Server) RemoveUser(userID string) error

func (*Server) RemoveUserKey

func (s *Server) RemoveUserKey(userID, keyID string) error

func (*Server) RevokeUser

func (s *Server) RevokeUser(userID string) error

func (*Server) SetAuthLife

func (s *Server) SetAuthLife(authLife time.Duration)

func (*Server) SetMinAppVersion

func (s *Server) SetMinAppVersion(minAppVersion *semver.Version)

func (*Server) SetOffline

func (s *Server) SetOffline(offline bool)

func (*Server) UnlabelMessage

func (s *Server) UnlabelMessage(userID, msgID, labelID string) error

type StatusHook added in v0.4.0

type StatusHook func(*http.Request) (int, bool)

StatusHook is a function that can be used to modify the response code of a call.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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