import (
"bufio"
- "encoding/json"
"errors"
"fmt"
"io"
- "io/ioutil"
"log"
"net/url"
"os"
"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.stargrave.org/sgblog"
)
Topics []string
}
-func serveGopher() {
- cfgPath := os.Args[2]
- cfgRaw, err := ioutil.ReadFile(cfgPath)
+func serveGopher(cfgPath string) {
+ cfg, err := readCfg(cfgPath)
if err != nil {
log.Fatalln(err)
}
- var cfgGeneral map[string]interface{}
- if err = hjson.Unmarshal(cfgRaw, &cfgGeneral); err != nil {
- log.Fatalln(err)
- }
- cfgRaw, err = json.Marshal(cfgGeneral)
- if err != nil {
- log.Fatalln(err)
- }
- var cfg *Cfg
- if err = json.Unmarshal(cfgRaw, &cfg); err != nil {
- log.Fatalln(err)
- }
if cfg.GopherDomain == "" {
log.Fatalln("GopherDomain is not configured")
}
"compress/gzip"
"crypto/sha1"
"encoding/hex"
- "encoding/json"
"encoding/xml"
"errors"
"fmt"
"hash"
"html"
"io"
- "io/ioutil"
"log"
"net/url"
"os"
"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.stargrave.org/sgblog"
"go.stargrave.org/sgblog/cmd/sgblog/atom"
"golang.org/x/crypto/blake2b"
if cfgPath == "" {
log.Fatalln("SGBLOG_CFG is not set")
}
- cfgRaw, err := ioutil.ReadFile(cfgPath)
+ cfg, err := readCfg(cfgPath)
if err != nil {
- makeErr(err)
- }
- var cfgGeneral map[string]interface{}
- if err = hjson.Unmarshal(cfgRaw, &cfgGeneral); err != nil {
- makeErr(err)
- }
- cfgRaw, err = json.Marshal(cfgGeneral)
- if err != nil {
- makeErr(err)
- }
- var cfg *Cfg
- if err = json.Unmarshal(cfgRaw, &cfg); err != nil {
- makeErr(err)
+ log.Fatalln(err)
}
+
pathInfo, exists := os.LookupEnv("PATH_INFO")
if !exists {
pathInfo = "/"
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()
}
package sgblog
const (
- Version = "0.16.0"
+ Version = "0.17.0"
WhenFmt = "2006-01-02 15:04:05Z07:00"
)