server

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 30 Imported by: 0

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

func WithDomain(domain string) Option

WithDomain controls the domain of the server.

func WithListener

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 WithMessageDedup

func WithMessageDedup() Option

func WithProxyOrigin

func WithProxyOrigin(origin string) Option

func WithProxyTransport

func WithProxyTransport(transport *http.Transport) Option

func WithRateLimit

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

func WithRateLimitAndCustomStatusCode

func WithRateLimitAndCustomStatusCode(limit int, window time.Duration, code int) Option

func WithServerConfig

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

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

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

func (*Server) AddMessageCreatedEvent

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

func (*Server) AddStatusHook

func (s *Server) AddStatusHook(fn StatusHook)

AddStatusHook adds a status hook to the server.

func (*Server) ChangeAddressType

func (s *Server) ChangeAddressType(userID, addrId string, addrType proton.AddressType) error

func (*Server) Close

func (s *Server) Close()

func (*Server) CreateAddress

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

func (*Server) CreateAddressAsUpdate

func (s *Server) CreateAddressAsUpdate(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

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) SetMaxUpdatesPerEvent

func (s *Server) SetMaxUpdatesPerEvent(max int)

SetMaxUpdatesPerEvent

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

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