riff

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: MPL-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeJSON           = "application/json"
	ContentTypeGraphQL        = "application/graphql"
	ContentTypeFormURLEncoded = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct{}

func (*API) Node

func (a *API) Node(name string) *api.Node

func (*API) Nodes

func (a *API) Nodes() api.Nodes

func (*API) Restart

func (a *API) Restart(name string) bool

func (*API) Service

func (a *API) Service(name string, state api.StateType) *api.Service

func (*API) Services

func (a *API) Services() api.Services

func (*API) Start

func (a *API) Start(name string) bool

func (*API) Stop

func (a *API) Stop(name string) bool

type Addresses

type Addresses struct {
	Http string `yaml:"http"` //http address
	Dns  string `yaml:"dns"`  //dns address
	Rpc  string `yaml:"rpc"`  //rpc address
}

type BodyWatch

type BodyWatch struct {
	Name  string `json:"name"`
	Type  string `json:"type"`
	Query string `json:"query"`
}

type Config

type Config struct {
	IP         string     `yaml:"ip"`          //server ip
	Name       string     `yaml:"name"`        //server random name
	DataCenter string     `yaml:"data_center"` //server data center
	Join       string     `yaml:"join"`        //join address
	AutoPilot  bool       `yaml:"auto_pilot"`  //auto join node
	Addresses  *Addresses `yaml:"addresses"`
	Ports      *Ports     `yaml:"ports"`
	Fanout     int        `yaml:"fan_out"`
}

func DefaultConfig

func DefaultConfig() *Config

func LoadConfig

func LoadConfig() *Config

type Deploy

type Deploy struct {
	Provider    string `yaml:"provider,omitempty"`
	Token       string `yaml:"token,omitempty"`
	Repository  string `yaml:"repository,omitempty"`
	Version     string `yaml:"version,omitempty"`
	Payload     string `yaml:"payload,omitempty"`
	ServicePath string `yaml:"service_path,omitempty"`
}

type Digest

type Digest struct {
	Name     string
	SnapShot string
}

type Http

type Http struct {
	Schema *graphql.Schema
	// contains filtered or unexported fields
}

func (*Http) Index

func (h *Http) Index(r *cart.Router)

type LogHandler

type LogHandler interface {
	HandleLog(string)
}

LogHandler interface is used for clients that want to subscribe to logs, for example to stream them over an IPC mechanism

type LogWriter

type LogWriter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

LogWriter implements io.Writer so it can be used as a log sink. It maintains a circular buffer of logs, and a set of handlers to which it can stream the logs to.

func NewLogWriter

func NewLogWriter(buf int) *LogWriter

NewLogWriter creates a LogWriter with the given buffer capacity

func (*LogWriter) DeregisterHandler

func (l *LogWriter) DeregisterHandler(lh LogHandler)

DeregisterHandler removes a LogHandler and prevents more invocations

func (*LogWriter) RegisterHandler

func (l *LogWriter) RegisterHandler(lh LogHandler)

RegisterHandler adds a log handler to receive logs, and sends the last buffered logs to the handler

func (*LogWriter) Write

func (l *LogWriter) Write(p []byte) (n int, err error)

Write is used to accumulate new logs

type Mutation

type Mutation struct{}

func (*Mutation) RegisteService

func (m *Mutation) RegisteService(config string, result *bool) error

func (*Mutation) Reload

func (m *Mutation) Reload(_ struct{}, result *bool) error

func (*Mutation) Service

func (m *Mutation) Service(p api.ParamServiceMutation, reply *bool) (err error)

func (*Mutation) UnregisteService

func (m *Mutation) UnregisteService(name string, result *bool) error

type MutationService

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

func (*MutationService) Cmd

func (r *MutationService) Cmd() string

func (*MutationService) Error

func (r *MutationService) Error() string

func (*MutationService) Ip

func (r *MutationService) Ip() string

func (*MutationService) Name

func (r *MutationService) Name() string

func (*MutationService) Port

func (r *MutationService) Port() int32

func (*MutationService) Success

func (r *MutationService) Success() bool

type MutationServiceInput

type MutationServiceInput struct {
	Port int32
	Cmd  string
	Name string
	Ip   string
}

type NestNodeResover

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

func (*NestNodeResover) Config

func (r *NestNodeResover) Config() string

func (*NestNodeResover) DataCenter

func (r *NestNodeResover) DataCenter() string

func (*NestNodeResover) Ip

func (r *NestNodeResover) Ip() string

func (*NestNodeResover) IsSelf

func (r *NestNodeResover) IsSelf() bool

func (*NestNodeResover) Name

func (r *NestNodeResover) Name() string

func (*NestNodeResover) Port

func (r *NestNodeResover) Port() int32

func (*NestNodeResover) Progress

func (r *NestNodeResover) Progress() *NestProgressResover

func (*NestNodeResover) RpcPort

func (r *NestNodeResover) RpcPort() int32

func (*NestNodeResover) SnapShot

func (r *NestNodeResover) SnapShot() string

func (*NestNodeResover) StartTime

func (r *NestNodeResover) StartTime() int32

func (*NestNodeResover) State

func (r *NestNodeResover) State() string

func (*NestNodeResover) StatusContent

func (r *NestNodeResover) StatusContent() string

func (*NestNodeResover) Version

func (r *NestNodeResover) Version() int32

type NestProgressResover

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

func (*NestProgressResover) Current

func (r *NestProgressResover) Current() int32

func (*NestProgressResover) InProgress

func (r *NestProgressResover) InProgress() bool

func (*NestProgressResover) Total

func (r *NestProgressResover) Total() int32

type NestServiceResover

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

func (*NestServiceResover) Config

func (r *NestServiceResover) Config() string

func (*NestServiceResover) Ip

func (r *NestServiceResover) Ip() string

func (*NestServiceResover) Name

func (r *NestServiceResover) Name() string

func (*NestServiceResover) Port

func (r *NestServiceResover) Port() int32

func (*NestServiceResover) Progress

func (r *NestServiceResover) Progress() *NestProgressResover

func (*NestServiceResover) StartTime

func (r *NestServiceResover) StartTime() int32

func (*NestServiceResover) State

func (r *NestServiceResover) State() string

func (*NestServiceResover) StatusContent

func (r *NestServiceResover) StatusContent() string

type Node

type Node struct {
	Name        string
	DataCenter  string
	IP          string
	RpcPort     int
	HttpPort    int
	Version     uint64
	State       api.StateType // Current state
	StateChange time.Time     // Time last state change happened
	SnapShot    string
	Services
	IsSelf bool
	// contains filtered or unexported fields
}

func (*Node) Address

func (n *Node) Address() string

func (*Node) LoadService

func (n *Node) LoadService(name string) *Service

func (*Node) LoadServices

func (n *Node) LoadServices()

func (*Node) Shutter

func (n *Node) Shutter()

func (*Node) String

func (n *Node) String() string

func (*Node) VersionGet

func (n *Node) VersionGet() uint64

func (*Node) VersionInc

func (n *Node) VersionInc() uint64

func (*Node) VersionSet

func (n *Node) VersionSet(v uint64)

Witness is called to update our local clock if necessary after witnessing a clock value received from another process

type NodeResolver

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

func (*NodeResolver) DataCenter

func (r *NodeResolver) DataCenter() string

func (*NodeResolver) HttpPort

func (r *NodeResolver) HttpPort() int32

func (*NodeResolver) Ip

func (r *NodeResolver) Ip() string

func (*NodeResolver) IsSelf

func (r *NodeResolver) IsSelf() bool

func (*NodeResolver) Name

func (r *NodeResolver) Name() string

func (*NodeResolver) RpcPort

func (r *NodeResolver) RpcPort() int32

func (*NodeResolver) Services

func (r *NodeResolver) Services() *[]*NestServiceResover

func (*NodeResolver) SnapShot

func (r *NodeResolver) SnapShot() string

func (*NodeResolver) State

func (r *NodeResolver) State() string

func (*NodeResolver) Version

func (r *NodeResolver) Version() int32

type Nodes

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

type Ports

type Ports struct {
	Http int `yaml:"http"` //http port default 8610
	Dns  int `yaml:"dns"`  //dns port default 8620
	Rpc  int `yaml:"rpc"`  //rpc port defalut 8630
}

type Progress

type Progress struct {
	Current    int32
	Total      int32
	InProgress bool
}

type Query

type Query struct{}

func (*Query) Node

func (q *Query) Node(p api.ParamNode, node *api.Node) error

func (*Query) Nodes

func (q *Query) Nodes(_ struct{}, nodes *api.Nodes) error

func (*Query) Service

func (q *Query) Service(p api.ParamService, service *api.Service) error

func (*Query) Services

func (q *Query) Services(_ struct{}, services *api.Services) error

func (*Query) SnapShot

func (q *Query) SnapShot(_ struct{}, snap *string) error

type RequestOptions

type RequestOptions struct {
	Query         string                 `json:"query" url:"query" schema:"query"`
	Variables     map[string]interface{} `json:"variables" url:"variables" schema:"variables"`
	OperationName string                 `json:"operationName" url:"operationName" schema:"operationName"`
}

type Resolver

type Resolver struct {
}

func (*Resolver) MutationService

func (*Resolver) MutationService(args struct {
	Services *[]*MutationServiceInput
}) *[]*MutationService

func (*Resolver) Node

func (*Resolver) Node(args struct{ Name string }) *NodeResolver

func (*Resolver) Nodes

func (*Resolver) Nodes() *[]*NodeResolver

func (*Resolver) RegisteService

func (*Resolver) RegisteService(args struct {
	Node struct {
		Ip   string
		Port int32
	}
	Config string
}) (*bool, error)

func (*Resolver) Riff

func (*Resolver) Riff() *RiffResolver

Query

func (*Resolver) Server

func (*Resolver) Server() *NodeResolver

func (*Resolver) Service

func (*Resolver) Service(args struct {
	Name  string
	State *string
}) *ServiceResolver

func (*Resolver) Services

func (*Resolver) Services() *[]*ServiceResolver

func (*Resolver) UnregisteService

func (*Resolver) UnregisteService(args struct {
	Node struct {
		Ip   string
		Port int32
	}
	Name string
}) *bool

type Riff

type Riff struct{}

func (*Riff) PushDiff

func (r *Riff) PushDiff(diff []*Node, remoteDiff *[]*Node) error

push changes

func (*Riff) Request

func (r *Riff) Request(snap string, digests *[]*Digest) error

push request a digest

type RiffResolver

type RiffResolver struct {
}

func (*RiffResolver) GitBranch

func (r *RiffResolver) GitBranch() string

func (*RiffResolver) GitSha

func (r *RiffResolver) GitSha() string

func (*RiffResolver) Version

func (r *RiffResolver) Version() string

type Server

type Server struct {
	Listener   net.Listener
	Logger     *log.Logger
	Self       *Node
	ShutdownCh chan struct{}
	SnapShot   string
	Nodes
	// contains filtered or unexported fields
}

func NewServer

func NewServer(config *Config) (*Server, error)

func (*Server) AddNode

func (s *Server) AddNode(n *Node)

func (*Server) AddService

func (s *Server) AddService(service *Service)

func (*Server) DeleteNode

func (s *Server) DeleteNode(key string)

func (*Server) ExchangeNode

func (s *Server) ExchangeNode(n, d *Node)

func (*Server) GetNode

func (s *Server) GetNode(key string) *Node

func (*Server) GetService

func (s *Server) GetService(findName string) interface{}

func (*Server) Keys

func (s *Server) Keys() []string

func (*Server) MakeDiffNodes

func (s *Server) MakeDiffNodes(digests []*Digest) (diff []*Node)

func (*Server) MakeDigest

func (s *Server) MakeDigest() (digests []*Digest)

func (*Server) MergeDiff

func (s *Server) MergeDiff(diffs []*Node) (reDiffs []*Node)

func (*Server) Range

func (s *Server) Range(f func(string, *Node) bool)

func (*Server) RemoveNodeDelay

func (s *Server) RemoveNodeDelay(n *Node)

func (*Server) ServicesSlice

func (s *Server) ServicesSlice() []string

func (*Server) SetState

func (s *Server) SetState(n *Node, state api.StateType) uint64

set node state version inc and shutter node return version++

func (*Server) SetStateOnly

func (s *Server) SetStateOnly(n *Node, state api.StateType) uint64

set node state version inc and shutter node return version

func (*Server) SetStateWithShutter

func (s *Server) SetStateWithShutter(n *Node, state api.StateType) uint64

SetState and make a snapsort return version ++

func (*Server) Shutdown

func (s *Server) Shutdown() error

func (*Server) Shutter

func (s *Server) Shutter()

func (*Server) Slice

func (s *Server) Slice() []*Node

func (*Server) String

func (s *Server) String() string

type Service

type Service struct {
	Version       uint64
	State         api.StateType //Current state
	StateChange   time.Time     //Time last state change happened
	Progress      *Progress     //update percent
	Config        string        //config file
	StartTime     time.Time     //start time
	StatusContent string        //status content
	*ServiceConfig
}

func (*Service) Address

func (s *Service) Address() string

func (*Service) GetPid

func (s *Service) GetPid() int

func (*Service) GetVersion

func (s *Service) GetVersion() string

func (*Service) IsExist

func (s *Service) IsExist() bool

func (*Service) RemovePid

func (s *Service) RemovePid() error

func (*Service) Restart

func (s *Service) Restart() error

func (*Service) SetPid

func (s *Service) SetPid(pid int)

func (*Service) SetVersion

func (s *Service) SetVersion(version string)

func (*Service) Start

func (s *Service) Start() error

func (*Service) Stop

func (s *Service) Stop() error

type ServiceConfig

type ServiceConfig struct {
	Name       string   `yaml:"name,omitempty"`
	Ip         string   `yaml:"ip,omitempty"`
	Port       int      `yaml:"port,omitempty"`
	Env        []string `yaml:"env,omitempty"`
	Dir        string   `yaml:"dir,omitempty"`
	Command    []string `yaml:"command,omitempty"`
	StatusPage string   `yaml:"status_page,omitempty"`
	PidFile    string   `yaml:"pid_file,omitempty"`
	StdOutFile string   `yaml:"std_out_file,omitempty"`
	StdErrFile string   `yaml:"std_err_file,omitempty"`
	Grace      bool     `yaml:"grace,omitempty"`
	RunAtLoad  bool     `yaml:"run_at_load,omitempty"`
	KeepAlive  bool     `yaml:"keep_alive,omitempty"`
	*Deploy    `yaml:"deploy,omitempty"`
}

type ServiceResolver

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

func (*ServiceResolver) Name

func (r *ServiceResolver) Name() string

func (*ServiceResolver) Nodes

func (r *ServiceResolver) Nodes() *[]*NestNodeResover

type Services

type Services map[string]*Service

func (*Services) Keys

func (s *Services) Keys() []string

type Watch

type Watch struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewWatch

func NewWatch() *Watch

func (*Watch) DeregisterHandler

func (w *Watch) DeregisterHandler(wh WatchHandler)

func (*Watch) Dispatch

func (w *Watch) Dispatch(param WatchParam)

func (*Watch) RegisterHandler

func (w *Watch) RegisterHandler(wh WatchHandler)

type WatchHandler

type WatchHandler interface {
	GetParam() *WatchParam
	HandleWatch()
}

type WatchParam

type WatchParam struct {
	Name      string `json:"name"`
	WatchType `json:"watchType"`
}

type WatchType

type WatchType int
const (
	NodeChanged WatchType = 1 << iota
	ServiceChanged
)

func (WatchType) String

func (w WatchType) String() string

type WsRequest

type WsRequest struct {
	Event string    `json:"event"`
	Body  BodyWatch `json:"body"`
}

type WsResponse

type WsResponse struct {
	Event string      `json:"event"`
	Body  interface{} `json:"body"`
}

Jump to

Keyboard shortcuts

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