haberdasher-twirp/cmd/main.go

41 lines
699 B
Go
Raw Normal View History

2021-07-26 14:00:25 +00:00
package main
import (
2021-07-27 00:47:29 +00:00
"fmt"
2021-07-26 14:00:25 +00:00
"net/http"
"os"
2021-07-27 00:47:29 +00:00
"path"
2021-07-26 14:00:25 +00:00
"haberdasher-twirp/haberdasher"
"haberdasher-twirp/internal/haberdasherserver"
)
func main() {
2021-07-27 00:47:29 +00:00
var cwd, dbPath, dbDir string
var err error
2021-07-26 14:00:25 +00:00
var bind string = ":8080"
2021-07-27 00:47:29 +00:00
cwd, err = os.Getwd()
dbPath = path.Join(cwd, "var/hat.db")
dbDir = path.Dir(dbPath)
if _, err = os.Stat(dbDir); os.IsNotExist(err) {
err = os.Mkdir(dbDir, 0700)
if err != nil {
fmt.Printf("boltdb: %s\n", err)
}
}
2021-07-26 14:00:25 +00:00
if len(os.Args) > 1 {
bind = os.Args[1]
}
2021-07-27 00:47:29 +00:00
fmt.Printf("boltdb: %s\n", dbPath)
server := &haberdasherserver.Server{DBPath: dbPath}
2021-07-26 14:00:25 +00:00
twirpHandler := haberdasher.NewHaberdasherServer(server)
http.ListenAndServe(bind, twirpHandler)
}