mirror of
https://github.com/Sean-Der/fail2rest.git
synced 2024-12-22 13:42:17 +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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Configuration struct {
|
||||||
|
Addr string
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
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()
|
r := mux.NewRouter()
|
||||||
GlobalHandler(r.PathPrefix("/global").Subrouter())
|
GlobalHandler(r.PathPrefix("/global").Subrouter())
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
http.ListenAndServe(":5000", nil)
|
http.ListenAndServe(configuration.Addr, nil)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue