51 lines
744 B
Go
51 lines
744 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"net/http"
|
|
|
|
"github.com/Xe/middleware"
|
|
"github.com/codegangsta/negroni"
|
|
|
|
"shuo-irc.com/config"
|
|
)
|
|
|
|
var (
|
|
conf *config.Config
|
|
|
|
confPath = flag.String("conf", "./scream.ini", "path to config file")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
var err error
|
|
conf, err = config.Load(*confPath)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
_ = conf
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
mux.HandleFunc("/config", func(rw http.ResponseWriter, req *http.Request) {
|
|
rw.Header().Set("Content-Type", "application/json")
|
|
|
|
body, err := json.MarshalIndent(conf, "", "\t")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
rw.Write(body)
|
|
})
|
|
|
|
n := negroni.Classic()
|
|
|
|
middleware.Inject(n)
|
|
n.UseHandler(mux)
|
|
|
|
n.Run(":" + conf.Info.Port)
|
|
}
|