server/server.go: 9P server in its own package
- server.New, server.Option, server.WithStrict, server.WithYolo - main.go is now just wiring and CLI - Clean package boundary: server/ = protocol, session/ = lifecycle, store/ = abstraction
This commit is contained in:
parent
d0ce8a108e
commit
56bcb87ff6
9
main.go
9
main.go
|
|
@ -14,6 +14,7 @@ import (
|
|||
"9fans.net/go/plan9/client"
|
||||
"ollie/pkg/env"
|
||||
olog "ollie/pkg/log"
|
||||
"olliesrv/server"
|
||||
)
|
||||
|
||||
const serviceName = "ollie"
|
||||
|
|
@ -160,14 +161,14 @@ func runServer(sockPath, pidPath string) {
|
|||
os.WriteFile(pidPath, []byte(fmt.Sprintf("%d", os.Getpid())), 0644) //nolint:errcheck
|
||||
|
||||
sink := olog.NewSink(os.Stdout, os.Stderr, olog.ParseLevel(os.Getenv("OLLIE_LOG"), olog.LevelWarn))
|
||||
var srvOpts []ServerOption
|
||||
var srvOpts []server.Option
|
||||
if *strict {
|
||||
srvOpts = append(srvOpts, WithStrict())
|
||||
srvOpts = append(srvOpts, server.WithStrict())
|
||||
}
|
||||
if *yolo {
|
||||
srvOpts = append(srvOpts, WithYolo())
|
||||
srvOpts = append(srvOpts, server.WithYolo())
|
||||
}
|
||||
srv := New(sink, srvOpts...)
|
||||
srv := server.New(sink, srvOpts...)
|
||||
|
||||
listener, err := net.Listen("unix", sockPath)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// 9P filesystem server for ollie sessions.
|
||||
// See doc comment below for filesystem layout.
|
||||
package main
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -80,14 +80,14 @@ type Server struct {
|
|||
groups map[string]map[string]bool // group → set of members
|
||||
}
|
||||
|
||||
// ServerOption configures the 9P server.
|
||||
type ServerOption func(*Server)
|
||||
// Option configures the 9P server.
|
||||
type Option func(*Server)
|
||||
|
||||
func WithStrict() ServerOption { return func(s *Server) { s.strict = true } }
|
||||
func WithYolo() ServerOption { return func(s *Server) { s.yolo = true } }
|
||||
func WithStrict() Option { return func(s *Server) { s.strict = true } }
|
||||
func WithYolo() Option { return func(s *Server) { s.yolo = true } }
|
||||
|
||||
// New creates a new Server.
|
||||
func New(sink *olog.Sink, opts ...ServerOption) *Server {
|
||||
func New(sink *olog.Sink, opts ...Option) *Server {
|
||||
memDir := defaultMemDir()
|
||||
os.MkdirAll(memDir, 0755) //nolint:errcheck
|
||||
transcriptDir := defaultTranscriptDir()
|
||||
Reference in New Issue