server

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: MIT Imports: 6 Imported by: 0

README

server

Altid server library and 9p client

GoDoc Tests Go Report Card License

9pd

go get github.com/altid/server/cmd/9pd

9pd will watch (by default, /tmp/altid) a path containing Altid services, and orchestrate access to them for a 9p-based Altid client.

Documentation

Overview

Package server is a library used to build Altid servers

go get github.com/altid/server

9pd

Additionally, this contains the canonical server for Altid, 9pd. It can be retrieved with the following

go get github.com/altid/server/cmd/9pd

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runner

type Runner interface {
	// Run will be called internally once services have been iterated and set up
	// name will be the name of the service, and initial will be the default buffer
	// Client should be initialized `c.Client(0)` and set to `initial`
	Run(context.Context, *Service) error
	// Address must return the IP + Port pair the server uses, for use with mDNS broadcasts internally
	Address() (string, string)
}

type Server

type Server struct {
	// Logger can be set to log server messages
	// such as buffer activity or control message writes
	Logger func(string, ...interface{})
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ctx context.Context, runner Runner, dir string) (*Server, error)

NewServer returns a server which watches the event files at `dir` the Runner will be called for each Service that is located, facilitating server access to underlying state

func (*Server) Listen

func (s *Server) Listen() error

Listen wraps calls to the Service's Run method it will return on unrecoverable errors

type Service

type Service struct {
	// The client manager is expected to be used whenever a client connects to a server
	// generally a server only has to call "c := client.Client(0)"
	// This adds the client to the stack using the special ID of 0
	// making sure to client.Remove(c.UUID) after you're done with it.
	// Clients will only receive events when they are registered!
	Client *client.Manager
	// Files holds the handlers to our internal file representations
	// The Normal and Stat methods return useful types
	// Generally, Normal returns an io.ReadWriter; but you should switch on all variants
	// Of io.Writer, io.Reader, io.ReaderAt, io.WriterAt, io.Seeker, and any combination therein
	// Additionally, if the file requested is a directory, a []*os.FileInfo will be returned instead
	// Stat will return an *os.FileInfo for a given file
	Files    *files.Files
	Commands chan *command.Command
	// contains filtered or unexported fields
}

func (*Service) Default

func (s *Service) Default() string

Default returns a known-good buffer name that can be used to set a starting buffer for a given client

c := client.Client(0) c.SetBuffer(service.Default)

Directories

Path Synopsis
Package client provides management of clients for a server go get github.com/altid/server/client
Package client provides management of clients for a server go get github.com/altid/server/client
cmd
9pd
Package files is a layer over a normal directory to synthesize Stat responses, and allow special semantics for Read/Write requests to opened files Adding import ( "os" "path" "github.com/altid/server/files" ) type NormalHandler struct{} func NewNormal() *NormalHandler { return &NormalHandler{} } func (*NormalHandler) Normal(msg *files.Message) (interface{}, error) { fp := path.Join(msg.Service, msg.Buffer, msg.Target) return os.Open(fp) } func (*NormalHandler) Stat(msg *files.Message) (os.FileInfo, error) { fp := path.Join(msg.Service, msg.Buffer, msg.Target) return os.Lstat(fp) } func main() { fh := files.Handle("/path/to/dir") fh.Add("/myfile", NewNormal()) // [...] }
Package files is a layer over a normal directory to synthesize Stat responses, and allow special semantics for Read/Write requests to opened files Adding import ( "os" "path" "github.com/altid/server/files" ) type NormalHandler struct{} func NewNormal() *NormalHandler { return &NormalHandler{} } func (*NormalHandler) Normal(msg *files.Message) (interface{}, error) { fp := path.Join(msg.Service, msg.Buffer, msg.Target) return os.Open(fp) } func (*NormalHandler) Stat(msg *files.Message) (os.FileInfo, error) { fp := path.Join(msg.Service, msg.Buffer, msg.Target) return os.Lstat(fp) } func main() { fh := files.Handle("/path/to/dir") fh.Add("/myfile", NewNormal()) // [...] }
internal
mdns
Package mdns is a convenience wrapper over github.com/grandcat/zeroconf for listing Altid services over mdns go get github.com/altid/server/mdns
Package mdns is a convenience wrapper over github.com/grandcat/zeroconf for listing Altid services over mdns go get github.com/altid/server/mdns
tabs
Package tabs contains helper functions for managing tabs in Altid services go get github.com/altid/server/tabs
Package tabs contains helper functions for managing tabs in Altid services go get github.com/altid/server/tabs
tail
Package tail mimicks the behaviour of `tail -f` tail watches an events file for writes and sends out matching events, one for each line written.
Package tail mimicks the behaviour of `tail -f` tail watches an events file for writes and sends out matching events, one for each line written.

Jump to

Keyboard shortcuts

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