session

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 53 Imported by: 0

Documentation

Index

Constants

View Source
const ApiRequestMaxDuration = time.Minute

Variables

View Source
var ApiRouter = http.NewServeMux()

Functions

func CreateAPIHost

func CreateAPIHost(session *Session) *vhttp.VirtualHost

func GetManifestPathFromArgs added in v0.2.0

func GetManifestPathFromArgs(args []string) string

func Match

func Match[T any, U any](path string, cb func(*Session, *http.Request, T) (U, error))

func MatchLocked

func MatchLocked[T any, U any](path string, cb func(*Session, *http.Request, T) (U, error))

func OpenAndServe added in v0.2.0

func OpenAndServe(manifestPath string)

func Run added in v0.2.0

func Run(args []string)

func ServeRPC

func ServeRPC(originalReq *http.Request, method string, body json.RawMessage) (out json.RawMessage, err error)

Forwards to serve HTTP

Types

type HostsLine

type HostsLine struct {
	Hostname string
	IP       string
}

func (*HostsLine) UnmarshalYAML

func (h *HostsLine) UnmarshalYAML(node *yaml.Node) error

type IPInfoOptions

type IPInfoOptions struct {
	Disable    bool     `yaml:"disable,omitempty"`
	MaxmindKey string   `yaml:"maxmind,omitempty"`
	Mark       []string `yaml:"mark,omitempty"`
}

func (IPInfoOptions) CreateProvider

func (i IPInfoOptions) CreateProvider() (info netx.IPInfoProvider)

type IPInfoQuery

type IPInfoQuery struct {
	IP string `json:"ip"`
}

type IPInfoResult

type IPInfoResult struct {
	IP      string `json:"ip"`
	ASN     uint32 `json:"asn"`
	Desc    string `json:"desc"`
	Country string `json:"country"`
	Flags   uint32 `json:"flags"`
}

type JetManifest

type JetManifest struct {
	Streams map[string]JetStreamManifest           `yaml:"streams,omitempty"`
	KV      map[string]jetstream.KeyValueConfig    `yaml:"kv,omitempty"`
	Obj     map[string]jetstream.ObjectStoreConfig `yaml:"obj,omitempty"`
}

func (*JetManifest) Init

type JetStreamManifest

type JetStreamManifest struct {
	Stream    jetstream.StreamConfig              `yaml:"stream"`
	Consumers map[string]jetstream.ConsumerConfig `yaml:"consumers"`
}

func (*JetStreamManifest) Init

type KVCompareAndSwap

type KVCompareAndSwap struct {
	Expected json.RawMessage `json:"expected"`
	Desired  json.RawMessage `json:"desired"`
}

type KVCompareAndSwapResult

type KVCompareAndSwapResult struct {
	OK       bool            `json:"ok"`
	Diff     json.RawMessage `json:"diff"`
	Revision uint64          `json:"revision"`
	Value    json.RawMessage `json:"value"`
}

type KVSetIf

type KVSetIf struct {
	Revision uint64          `json:"revision"`
	Value    json.RawMessage `json:"value"`
}

type KVState

type KVState struct {
	Revision uint64          `json:"revision"`
	Value    json.RawMessage `json:"value"`
}

type Lambda

type Lambda struct {
	ID        string      `json:"id"`
	Timestamp time.Time   `json:"timestamp"`
	Code      string      `json:"code"`
	Headers   http.Header `json:"headers"`
	// contains filtered or unexported fields
}

type LambdaID

type LambdaID struct {
	MachineID config.MachineID
	UID       snowflake.ID
}

func NewLambdaID

func NewLambdaID() LambdaID

func (LambdaID) IsZero

func (l LambdaID) IsZero() bool

func (LambdaID) MarshalBinary

func (l LambdaID) MarshalBinary() ([]byte, error)

func (LambdaID) MarshalText

func (l LambdaID) MarshalText() ([]byte, error)

func (LambdaID) Peer

func (l LambdaID) Peer(session *Session) *xpost.Peer

func (LambdaID) String

func (l LambdaID) String() string

func (*LambdaID) UnmarshalBinary

func (l *LambdaID) UnmarshalBinary(data []byte) error

func (*LambdaID) UnmarshalText

func (l *LambdaID) UnmarshalText(data []byte) error

type LockedHandler

type LockedHandler struct {
	Handler http.Handler
}

func (LockedHandler) ServeHTTP

func (h LockedHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type Manifest

type Manifest struct {
	Root         string                                   `yaml:"root,omitempty"`          // Root directory
	ServiceRoot  string                                   `yaml:"service_root,omitempty"`  // Service root directory
	Services     util.OrderedMap[string, service.Service] `yaml:"services,omitempty"`      // Services
	Server       map[string]*Server                       `yaml:"server,omitempty"`        // Virtual hosts
	IPInfo       IPInfoOptions                            `yaml:"ipinfo,omitempty"`        // IP information provider
	Env          map[string]string                        `yaml:"env,omitempty"`           // Environment variables
	Runners      map[string]*Runner                       `yaml:"runners,omitempty"`       // Runners
	Jet          JetManifest                              `yaml:"jet,omitempty"`           // JetStream configuration
	Hosts        []HostsLine                              `yaml:"hosts,omitempty"`         // Hostname to IP mapping
	CustomErrors string                                   `yaml:"custom_errors,omitempty"` // Path to custom error pages
}

func LoadManifest

func LoadManifest(manifestPath string) (*Manifest, error)

type PullResult

type PullResult struct {
	From revision.Reference `json:"from"` // From reference
	To   revision.Reference `json:"to"`   // To reference
}

type RepoInfo

type RepoInfo struct {
	Sys    string             `json:"sys"`    // Repository system
	Ref    revision.Reference `json:"ref"`    // Repository reference
	Remote revision.Reference `json:"remote"` // Remote repository reference
	URL    string             `json:"url"`    // Remote repository URL
}

type Runner

type Runner struct {
	Route        vhttp.HandleMux   `yaml:"route,omitempty"`          // HTTP route for the task
	Schedule     []ScheduledRunner `yaml:"schedule,omitempty"`       // Schedule for the task
	Rate         rate.Rate         `yaml:"rate,omitempty"`           // Rate limit for the task
	NoDeadLetter bool              `yaml:"no_dead_letter,omitempty"` // Do not send to dead letter
	retry.Policy `yaml:",inline"`
}

func (*Runner) ConsumeCore added in v0.3.2

func (t *Runner) ConsumeCore(ctx context.Context, gw *enats.Gateway, subj, queue string) (err error)

func (*Runner) ConsumeJetstream added in v0.3.2

func (t *Runner) ConsumeJetstream(ctx context.Context, gw *enats.Gateway, cns jetstream.Consumer) error

func (*Runner) Listen

func (t *Runner) Listen(ctx context.Context, gw *enats.Gateway, topic string) (cancel context.CancelFunc, err error)

func (*Runner) ServeCore added in v0.3.2

func (t *Runner) ServeCore(ctx context.Context, gw *enats.Gateway, msg *nats.Msg)

func (*Runner) ServeJetstream added in v0.3.2

func (t *Runner) ServeJetstream(ctx context.Context, gw *enats.Gateway, msg jetstream.Msg)

func (*Runner) ServeMsg

func (t *Runner) ServeMsg(ctx context.Context, subject string, data []byte, meta *jetstream.MsgMetadata, headers nats.Header) (res []byte, err error)

type ScheduledRunner

type ScheduledRunner struct {
	Interval util.Duration `yaml:"interval,omitempty"`
	Topic    string        `yaml:"topic,omitempty"`
	Payload  any           `yaml:"payload,omitempty"`
}

func (*ScheduledRunner) Run

func (sch *ScheduledRunner) Run(ctx context.Context, idx int, gw *enats.Gateway, topic, queueName string)

type Server

type Server struct {
	vhttp.VirtualHostOptions `yaml:",inline"`
	Router                   vhttp.HandleMux `yaml:"router,omitempty"`
}

func (*Server) CreateVirtualHost

func (sv *Server) CreateVirtualHost() *vhttp.VirtualHost

type ServiceCommandResult

type ServiceCommandResult struct {
	Count int `json:"count"`
}

type ServiceEntry

type ServiceEntry struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type ServiceHealth

type ServiceHealth struct {
	Status  string `json:"status"`        // Status
	Healthy int    `json:"healthy"`       // Number of healthy instances
	Total   int    `json:"total"`         // Total number of instances
	Err     string `json:"err,omitempty"` // Error message
}

func (*ServiceHealth) Fill

func (h *ServiceHealth) Fill(sv *ServiceState)

type ServiceInvalidate

type ServiceInvalidate struct {
	Invalidate bool `json:"invalidate"`
}

type ServiceList

type ServiceList struct {
	Services []ServiceEntry `json:"services"`
}

type ServiceMetrics

type ServiceMetrics struct {
	ID        snowflake.ID              `json:"id"`
	Type      string                    `json:"type"`
	Server    lb.LoadBalancerMetrics    `json:"server"`
	Processes []service.ProcTreeMetrics `json:"processes"`
	ServiceHealth
}

func (*ServiceMetrics) Fill

func (m *ServiceMetrics) Fill(sv *ServiceState)

type ServiceState

type ServiceState struct {
	service.Instance

	ID snowflake.ID
	// contains filtered or unexported fields
}

func (*ServiceState) Err

func (s *ServiceState) Err() error

func (*ServiceState) GetLoadBalancer

func (s *ServiceState) GetLoadBalancer() (*lb.LoadBalancer, bool)

func (*ServiceState) GetProcessTrees

func (s *ServiceState) GetProcessTrees() ([]service.ProcessTree, bool)

func (*ServiceState) Shutdown

func (s *ServiceState) Shutdown(ctx context.Context)

func (*ServiceState) Stop

func (s *ServiceState) Stop()

type Session

type Session struct {
	ID      snowflake.ID
	Context context.Context
	Cancel  context.CancelFunc
	Server  *vhttp.Server

	Nats     *enats.Gateway
	Peerlist *xpost.Peerlist

	ManifestPath      string // immut
	ServiceMap        concurrent.Map[string, *ServiceState]
	TaskSubscriptions []context.CancelFunc
	util.TimedMutex
	// contains filtered or unexported fields
}

func New

func New(path string) (s *Session, err error)

func RequestSession

func RequestSession(r *http.Request) *Session

func (*Session) Close

func (s *Session) Close() error

func (*Session) Manifest

func (s *Session) Manifest() *Manifest

func (*Session) Open

func (s *Session) Open(ctx context.Context) error

func (*Session) Reload

func (s *Session) Reload(invalidate bool) error

func (*Session) ReloadLocked

func (s *Session) ReloadLocked(invalidate bool) error

func (*Session) ResolveNats

func (s *Session) ResolveNats() *enats.Client

func (*Session) ResolveService

func (s *Session) ResolveService(sv string) vhttp.Handler

func (*Session) RestartService

func (s *Session) RestartService(match *string, invalidate bool) int

func (*Session) Shutdown

func (s *Session) Shutdown(ctx context.Context)

func (*Session) StartService

func (s *Session) StartService(name string, sv service.Service, invalidate bool) (*ServiceState, error)

func (*Session) StopService

func (s *Session) StopService(match *string) int

type SessionMetrics

type SessionMetrics struct {
	NumClients int                            `json:"num_clients"`
	Clients    map[string]vhttp.ClientMetrics `json:"sessions"`
}

type SystemMetrics

type SystemMetrics struct {
	MachineID            string             `json:"machine_id"`
	CPU                  cpu.InfoStat       `json:"cpu"`
	Load                 float64            `json:"load"`
	Rx                   float64            `json:"rx"`
	Tx                   float64            `json:"tx"`
	FreeDisk             uint64             `json:"freedisk"`
	FreeMem              uint64             `json:"freemem"`
	TotalDisk            uint64             `json:"totaldisk"`
	TotalMem             uint64             `json:"totalmem"`
	Uptime               uint64             `json:"uptime"` // seconds
	Hostname             string             `json:"hostname"`
	UID                  string             `json:"uid"`
	ProcessCount         uint64             `json:"process_count"`
	OS                   string             `json:"os"`
	KernelVersion        string             `json:"kernel_version"`
	KernelArch           string             `json:"kernel_arch"`
	VirtualizationSystem string             `json:"virtualization_system"`
	VirtualizationRole   string             `json:"virtualization_role"`
	RTT                  map[string]float64 `json:"rtt"`
}

func GetSystemMetrics

func GetSystemMetrics(session *Session) (m SystemMetrics)

type TypedHandler

type TypedHandler[T any, U any] struct {
	Callback func(*Session, *http.Request, T) (U, error)
}

Handler: func(arg T, req *http.Request) (result U, err error)

func (TypedHandler[T, U]) ServeHTTP

func (h TypedHandler[T, U]) ServeHTTP(w http.ResponseWriter, req *http.Request)

type UpdateParams

type UpdateParams struct {
	Invalidate bool `json:"invalidate"` // True if the session should be invalidated
}

Jump to

Keyboard shortcuts

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