mirror of
https://github.com/Sean-Der/fail2rest.git
synced 2024-12-22 21:52:18 +01:00
Add config file, Addr is configured via config
This commit is contained in:
parent
de70086c1b
commit
865a7e49a4
2 changed files with 26 additions and 1 deletions
3
config.json
Normal file
3
config.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"Addr": "0.0.0.0:5000"
|
||||
}
|
24
main.go
24
main.go
|
@ -1,13 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
Addr string
|
||||
}
|
||||
|
||||
func main() {
|
||||
file, fileErr := os.Open("config.json")
|
||||
|
||||
if fileErr != nil {
|
||||
fmt.Println("failed to open config:", fileErr)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
configuration := new(Configuration)
|
||||
configErr := json.NewDecoder(file).Decode(configuration)
|
||||
|
||||
if configErr != nil {
|
||||
fmt.Println("config error:", configErr)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
r := mux.NewRouter()
|
||||
GlobalHandler(r.PathPrefix("/global").Subrouter())
|
||||
http.Handle("/", r)
|
||||
http.ListenAndServe(":5000", nil)
|
||||
http.ListenAndServe(configuration.Addr, nil)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue