X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=cmd%2Fsgblog%2Fmain.go;h=b373564cbcd6dd31d14efeb17720862af395a392;hb=d28829ba288452dabf46cc42f45548dd54df64e9;hp=7603d125b80d5b45f7ca1b0bc3b0506761aea93b;hpb=cc110e327d5df988f9a5d94c02af5673e05f9b73;p=sgblog.git diff --git a/cmd/sgblog/main.go b/cmd/sgblog/main.go index 7603d12..b373564 100644 --- a/cmd/sgblog/main.go +++ b/cmd/sgblog/main.go @@ -21,9 +21,10 @@ package main import ( "bytes" "crypto/sha1" + "encoding/json" + "flag" "fmt" "io/ioutil" - "os" "regexp" "sort" "strings" @@ -32,6 +33,7 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" + "github.com/hjson/hjson-go" "go.cypherpunks.ru/recfile" ) @@ -195,9 +197,37 @@ func initRepo(cfg *Cfg) (*plumbing.Hash, error) { return &headHash, nil } +func readCfg(cfgPath string) (*Cfg, error) { + cfgRaw, err := ioutil.ReadFile(cfgPath) + if err != nil { + return nil, err + } + var cfgGeneral map[string]interface{} + if err = hjson.Unmarshal(cfgRaw, &cfgGeneral); err != nil { + return nil, err + } + cfgRaw, err = json.Marshal(cfgGeneral) + if err != nil { + return nil, err + } + var cfg *Cfg + if err = json.Unmarshal(cfgRaw, &cfg); err != nil { + return nil, err + } + return cfg, nil +} + func main() { - if len(os.Args) == 3 && os.Args[1] == "-gopher" { - serveGopher() + gopherCfgPath := flag.String("gopher", "", "Path to gopher-related configuration file") + flag.Usage = func() { + fmt.Fprintf(flag.CommandLine.Output(), `Usage of sgblog: + sgblog -- run CGI HTTP backend + sgblog -gopher /path/to/cfg.hjson -- run UCSPI/inetd Gopher backend +`) + } + flag.Parse() + if *gopherCfgPath != "" { + serveGopher(*gopherCfgPath) } else { serveHTTP() }