Add demo project
This commit is contained in:
parent
2dc27e62c5
commit
abe48658a3
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"app_name": "Awesome App",
|
||||
"version": 1.4,
|
||||
"debug": true,
|
||||
"database": {
|
||||
"adapter": "mysql",
|
||||
"host": "127.0.0.1",
|
||||
"port": 3306,
|
||||
"username": "root",
|
||||
"password": ""
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
|
||||
"github.com/localhots/secondly"
|
||||
)
|
||||
|
||||
// testConf is our app's configuration
|
||||
type testConf struct {
|
||||
AppName string `json:"app_name"`
|
||||
Version float32 `json:"version"`
|
||||
Debug bool `json:"debug"`
|
||||
Database testDatabaseConf `json:"database"`
|
||||
}
|
||||
|
||||
type testDatabaseConf struct {
|
||||
Adapter string `json:"adapter"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// conf is the variable that holds configuration
|
||||
var conf = testConf{}
|
||||
|
||||
func main() {
|
||||
// Setting up flags
|
||||
secondly.SetupFlags()
|
||||
flag.Parse()
|
||||
|
||||
// Delegating configuration management to Secondly
|
||||
secondly.Manage(&conf)
|
||||
// Handling file system events
|
||||
secondly.HandleFSEvents()
|
||||
// Starting a web server
|
||||
secondly.StartServer("", 5500)
|
||||
// Defining callbacks
|
||||
secondly.OnChange("AppName", func(o, n interface{}) {
|
||||
log.Printf("OMG! AppName changed from %q to %q", o, n)
|
||||
})
|
||||
|
||||
// Other application startup logic
|
||||
select {}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 80 KiB |
|
@ -23,13 +23,14 @@ func readFile(file string) ([]byte, error) {
|
|||
}
|
||||
|
||||
func writeFile(file string, body []byte) error {
|
||||
var fd *os.File
|
||||
var err error
|
||||
if ok := fileExist(file); !ok {
|
||||
if err = mkdirp(file); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var fd *os.File
|
||||
if fd, err = os.OpenFile(file, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, filePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue