|
- package main
-
- import (
- "fmt"
- "log"
- "net/http"
- "net/http/httputil"
- )
-
- //PathsConfig all system available pathes
- type PathsConfig struct {
- CRMAttachment string `json:"crm_attachmeng"`
- Angular2App string `json:"angular2_app"`
- }
-
- //GlobalPath all global pathes configurations
- var GlobalPath = PathsConfig{
- "/tmp/",
- "/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist/"}
-
- func main() {
- err := readConfig() //wechat API config
- if err != nil {
- log.Println(err)
- log.Fatal("unable to read server_config.json, program quit")
- return
- }
-
- err = readCRMConfig()
- if err != nil {
- log.Println(err)
- log.Fatal("unable to read crm_config.json, program quit")
- }
-
- setupRootFileServer()
-
- //setup handler
- //http.HandleFunc("/", webrootHandler)
- http.HandleFunc("/api", apiV1Main)
- http.HandleFunc("/upload", uploadHandler)
- http.HandleFunc("/crmfiles/", crmAttachmentHandler)
- http.HandleFunc("/dumprequest", dumpReuestHandler)
- http.ListenAndServe(":65500", nil)
- }
-
- func setupRootFileServer() {
- http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- http.ServeFile(w, r, GlobalPath.Angular2App+r.URL.Path[1:])
- })
-
- //fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/ng2-admin/dist"))
- //http.Handle("/test", http.StripPrefix("/test", fs))
-
- //fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist"))
- //http.Handle("/", fs)
- }
-
- func dumpReuestHandler(w http.ResponseWriter, r *http.Request) {
- logRequestDebug(httputil.DumpRequest(r, true))
- w.Header().Set("Content-Type", "application/json; charset=utf-8")
- w.Header().Set("Access-Control-Allow-Origin", "*")
- fmt.Fprintf(w, "{'status':'ok','msg':'done'}")
- }
|