rewrite most code; removes database to solely rely on config file
This commit is contained in:
parent
32bf03dc07
commit
ef22e29cef
10 changed files with 246 additions and 249 deletions
20
main.go
20
main.go
|
|
@ -2,34 +2,22 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
type tomlConfig struct {
|
||||
Database databaseConfig
|
||||
}
|
||||
|
||||
var config tomlConfig
|
||||
|
||||
func main() {
|
||||
var configPath string
|
||||
flag.StringVar(&configPath, "config", "config.toml", "path to config file")
|
||||
flag.Parse()
|
||||
|
||||
_, err := toml.DecodeFile(configPath, &config)
|
||||
cfg, err := LoadConfig(configPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
db, err := prepareDatabase()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
http.HandleFunc("/", basicAuth(db))
|
||||
err = http.ListenAndServe(":3002", nil)
|
||||
http.HandleFunc("/", RequestHandler(cfg))
|
||||
err = http.ListenAndServe(fmt.Sprintf(":%d", cfg.ServerPort), nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue