bacheca/cmd/bacheca-static/main.go

60 lines
1.5 KiB
Go

package main
import (
"context"
"flag"
"fmt"
"strings"
svc "git.abbiamoundominio.org/hamcha/bacheca"
proto "git.abbiamoundominio.org/hamcha/bacheca/proto"
"git.abbiamoundominio.org/hamcha/bacheca/storage"
boltbackend "git.abbiamoundominio.org/hamcha/bacheca/storage/bolt"
filebackend "git.abbiamoundominio.org/hamcha/bacheca/storage/file"
)
func main() {
format := flag.String("fmt", "rss", "Feed format (rss, atom, json)")
dbtype := flag.String("storage.type", "bolt", "Storage backend type")
dbfile := flag.String("storage.file", "bacheca.db", "Storage file or path, for file-based backends (bolt)")
flag.Parse()
ftype := strings.ToUpper(*format)
fid, ok := proto.GetFeedRequest_FeedType_value[ftype]
if !ok {
panic("invalid format (-fmt), check help for supported formats")
}
var backend storage.Backend
switch *dbtype {
case "bolt":
boltdb, err := boltbackend.MakeBoltBackend(*dbfile)
if err != nil {
panic(err)
}
defer boltdb.Close()
backend = boltdb
case "file":
filebackend, err := filebackend.MakeFileBackend(*dbfile)
if err != nil {
panic(err)
}
backend = filebackend
default:
panic("unknown storage backend type (-storage.type), check help for supported backends")
}
s := svc.MakeService(backend)
req := &proto.GetFeedRequest{
FeedType: proto.GetFeedRequest_FeedType(fid),
}
rsp := &proto.GetFeedResponse{}
err := s.GetFeed(context.Background(), req, rsp)
if err != nil {
panic(err)
}
fmt.Print(rsp.Data)
}