41 lines
699 B
Go
41 lines
699 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"path"
|
|
|
|
"haberdasher-twirp/haberdasher"
|
|
"haberdasher-twirp/internal/haberdasherserver"
|
|
)
|
|
|
|
func main() {
|
|
var cwd, dbPath, dbDir string
|
|
var err error
|
|
|
|
var bind string = ":8080"
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
if len(os.Args) > 1 {
|
|
bind = os.Args[1]
|
|
}
|
|
|
|
fmt.Printf("boltdb: %s\n", dbPath)
|
|
|
|
server := &haberdasherserver.Server{DBPath: dbPath}
|
|
twirpHandler := haberdasher.NewHaberdasherServer(server)
|
|
|
|
http.ListenAndServe(bind, twirpHandler)
|
|
}
|