Compare commits

..

No commits in common. "a87c941bb31fe3fb9cd2b10eddeabd7be487126f" and "9e0a4cac7213b6d43c438ddaff4d1f605ee4ab26" have entirely different histories.

5 changed files with 2 additions and 101 deletions

2
.gitignore vendored
View File

@ -1,5 +1,3 @@
*.swp
#
# ---> Go
# Binaries for programs and plugins
*.exe

2
go.mod
View File

@ -1,5 +1,3 @@
module git.tilde.town/tildetown/bbj2
go 1.18
require gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b

4
go.sum
View File

@ -1,4 +0,0 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -1,51 +0,0 @@
package main
import (
"fmt"
"os"
yaml "gopkg.in/yaml.v3"
)
const (
defaultPort = 7099
defaultInstanceName = "BBJ"
defaultHost = "127.0.0.1"
)
type Config struct {
Admins []string
Port int
Host string
InstanceName string `yaml:"instance_name"`
AllowAnon bool `yaml:"allow_anon"`
Debug bool
}
func parseConfig(configPath string) (*Config, error) {
cfgBytes, err := os.ReadFile(configPath)
if err != nil {
return nil, fmt.Errorf("failed to read config file: %w", err)
}
var cfg Config
if err := yaml.Unmarshal(cfgBytes, &cfg); err != nil {
return nil, fmt.Errorf("failed to parse config: %w", err)
}
if cfg.Port == 0 {
cfg.Port = defaultPort
}
if cfg.InstanceName == "" {
cfg.InstanceName = defaultInstanceName
}
if cfg.Host == "" {
cfg.Host = defaultHost
}
return &cfg, nil
}

View File

@ -1,47 +1,7 @@
package main
import (
"flag"
"fmt"
"io"
"os"
)
type iostreams struct {
Err io.Writer
Out io.Writer
}
type Opts struct {
ConfigPath string
IO iostreams
}
import "fmt"
func main() {
var configFlag = flag.String("config", "config.yml", "A path to a config file.")
flag.Parse()
opts := Opts{
ConfigPath: *configFlag,
IO: iostreams{
Err: os.Stderr,
Out: os.Stdout,
},
}
err := _main(opts)
if err != nil {
fmt.Fprintf(os.Stderr, "failed: %s", err)
}
}
func _main(opts Opts) error {
cfg, err := parseConfig(opts.ConfigPath)
if err != nil {
fmt.Fprintf(os.Stderr, "could not read config file '%s'", opts.ConfigPath)
os.Exit(1)
}
fmt.Printf("DBG %#v\n", cfg.InstanceName)
return nil
fmt.Println("bbj2 server")
}