riff

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: MPL-2.0 Imports: 34 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

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

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 added in v0.0.2

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 added in v0.0.8

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

func (*Mutation) Reload added in v0.0.6

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 added in v0.0.8

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

type MutationService added in v0.0.5

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

func (*MutationService) Cmd added in v0.0.5

func (r *MutationService) Cmd() string

func (*MutationService) Error added in v0.0.5

func (r *MutationService) Error() string

func (*MutationService) Ip added in v0.0.5

func (r *MutationService) Ip() string

func (*MutationService) Name added in v0.0.5

func (r *MutationService) Name() string

func (*MutationService) Port added in v0.0.5

func (r *MutationService) Port() int32

func (*MutationService) Success added in v0.0.5

func (r *MutationService) Success() bool

type MutationServiceInput added in v0.0.5

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

type NestNodeResover added in v0.0.5

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

func (*NestNodeResover) Config added in v0.0.5

func (r *NestNodeResover) Config() string

func (*NestNodeResover) DataCenter added in v0.0.5

func (r *NestNodeResover) DataCenter() string

func (*NestNodeResover) Ip added in v0.0.5

func (r *NestNodeResover) Ip() string

func (*NestNodeResover) IsSelf added in v0.0.5

func (r *NestNodeResover) IsSelf() bool

func (*NestNodeResover) Name added in v0.0.5

func (r *NestNodeResover) Name() string

func (*NestNodeResover) Port added in v0.0.5

func (r *NestNodeResover) Port() int32

func (*NestNodeResover) Progress added in v0.0.9

func (r *NestNodeResover) Progress() *NestProgressResover

func (*NestNodeResover) RpcPort added in v0.0.5

func (r *NestNodeResover) RpcPort() int32

func (*NestNodeResover) SnapShot added in v0.0.5

func (r *NestNodeResover) SnapShot() string

func (*NestNodeResover) StartTime added in v0.0.10

func (r *NestNodeResover) StartTime() int32

func (*NestNodeResover) State added in v0.0.5

func (r *NestNodeResover) State() string

func (*NestNodeResover) StatusContent added in v0.0.6

func (r *NestNodeResover) StatusContent() string

func (*NestNodeResover) Version added in v0.0.5

func (r *NestNodeResover) Version() int32

type NestProgressResover added in v0.0.9

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

func (*NestProgressResover) Current added in v0.0.9

func (r *NestProgressResover) Current() int32

func (*NestProgressResover) InProgress added in v0.0.9

func (r *NestProgressResover) InProgress() bool

func (*NestProgressResover) Total added in v0.0.9

func (r *NestProgressResover) Total() int32

type NestServiceResover added in v0.0.5

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

func (*NestServiceResover) Config added in v0.0.5

func (r *NestServiceResover) Config() string

func (*NestServiceResover) Ip added in v0.0.6

func (r *NestServiceResover) Ip() string

func (*NestServiceResover) Name added in v0.0.5

func (r *NestServiceResover) Name() string

func (*NestServiceResover) Port added in v0.0.5

func (r *NestServiceResover) Port() int32

func (*NestServiceResover) Progress added in v0.0.9

func (r *NestServiceResover) Progress() *NestProgressResover

func (*NestServiceResover) StartTime added in v0.0.10

func (r *NestServiceResover) StartTime() int32

func (*NestServiceResover) State added in v0.0.5

func (r *NestServiceResover) State() string

func (*NestServiceResover) StatusContent added in v0.0.6

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 added in v0.0.5

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

func (*NodeResolver) DataCenter added in v0.0.5

func (r *NodeResolver) DataCenter() string

func (*NodeResolver) HttpPort added in v0.0.6

func (r *NodeResolver) HttpPort() int32

func (*NodeResolver) Ip added in v0.0.5

func (r *NodeResolver) Ip() string

func (*NodeResolver) IsSelf added in v0.0.5

func (r *NodeResolver) IsSelf() bool

func (*NodeResolver) Name added in v0.0.5

func (r *NodeResolver) Name() string

func (*NodeResolver) RpcPort added in v0.0.6

func (r *NodeResolver) RpcPort() int32

func (*NodeResolver) Services added in v0.0.5

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

func (*NodeResolver) SnapShot added in v0.0.5

func (r *NodeResolver) SnapShot() string

func (*NodeResolver) State added in v0.0.5

func (r *NodeResolver) State() string

func (*NodeResolver) Version added in v0.0.5

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 added in v0.0.9

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 added in v0.0.5

type Resolver struct {
}

func (*Resolver) MutationService added in v0.0.5

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

func (*Resolver) Node added in v0.0.5

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

func (*Resolver) Nodes added in v0.0.5

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

func (*Resolver) RegisteService added in v0.0.6

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

func (*Resolver) Riff added in v0.0.5

func (_ *Resolver) Riff() *RiffResolver

Query

func (*Resolver) Server added in v0.0.5

func (_ *Resolver) Server() *NodeResolver

func (*Resolver) Service added in v0.0.5

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

func (*Resolver) Services added in v0.0.5

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

func (*Resolver) UnregisteService added in v0.0.6

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 added in v0.0.5

type RiffResolver struct {
}

func (*RiffResolver) GitBranch added in v0.0.5

func (r *RiffResolver) GitBranch() string

func (*RiffResolver) GitSha added in v0.0.5

func (r *RiffResolver) GitSha() string

func (*RiffResolver) Version added in v0.0.5

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 added in v0.0.6

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"`
	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 added in v0.0.5

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

func (*ServiceResolver) Name added in v0.0.5

func (r *ServiceResolver) Name() string

func (*ServiceResolver) Nodes added in v0.0.5

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 added in v0.0.2

func (w WatchType) String() string

type WsRequest added in v0.0.2

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

type WsResponse added in v0.0.2

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