Skip to content

Commit

Permalink
Merge pull request #215 from negbie/master
Browse files Browse the repository at this point in the history
Persist webconfig
  • Loading branch information
negbie committed Mar 20, 2019
2 parents 6402dbe + 77844f9 commit dce51f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
NAME?=heplify-server

all:
go build -ldflags "-s -w" -o $(NAME) cmd/heplify-server/*.go

debug:
go build -o $(NAME) cmd/heplify-server/*.go

.PHONY: clean
clean:
rm -fr $(NAME)
1 change: 1 addition & 0 deletions cmd/heplify-server/heplify-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func main() {
logp.Info("Successfull config reloaded from %v", r.RemoteAddr)
endServer()
config.Setting = *cfg
logp.SetToSyslog(config.Setting.LogSys, "")
tmpl.Execute(w, config.Setting)
startServer()
})
Expand Down
9 changes: 9 additions & 0 deletions config/webconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package config
import (
"fmt"
"net/http"
"os"
"reflect"
"strconv"

toml "github.com/BurntSushi/toml"
)

func WebConfig(r *http.Request) (*HeplifyServer, error) {
Expand Down Expand Up @@ -87,6 +90,12 @@ func WebConfig(r *http.Request) (*HeplifyServer, error) {
return nil, fmt.Errorf("Equal config")
}

f, err := os.Create(webSetting.Config)
if err != nil {
return &webSetting, nil
}
e := toml.NewEncoder(f)
e.Encode(webSetting)
return &webSetting, nil
}

Expand Down

0 comments on commit dce51f8

Please sign in to comment.