import (
"bytes"
"crypto/sha1"
+ "encoding/json"
+ "flag"
"fmt"
"io/ioutil"
- "os"
"regexp"
"sort"
"strings"
"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"
)
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()
}