Pārlūkot izejas kodu

hook upload handler and add configurable path for augnlar2app

master
Patrick Peng Sun pirms 8 gadiem
vecāks
revīzija
d0308e6538
1 mainītis faili ar 18 papildinājumiem un 5 dzēšanām
  1. +18
    -5
      main.go

+ 18
- 5
main.go Parādīt failu

//PathsConfig all system available pathes //PathsConfig all system available pathes
type PathsConfig struct { type PathsConfig struct {
CRMAttachment string `json:"crm_attachmeng"` CRMAttachment string `json:"crm_attachmeng"`
Angular2App string `json:"angular2_app"`
} }


//GlobalPath all global pathes configurations //GlobalPath all global pathes configurations
var GlobalPath = PathsConfig{"/tmp/"}
var GlobalPath = PathsConfig{
"/tmp/",
"/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist/"}


func main() { func main() {
err := readConfig() //wechat API config err := readConfig() //wechat API config
log.Fatal("unable to read crm_config.json, program quit") log.Fatal("unable to read crm_config.json, program quit")
} }


//fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/ng2-admin/dist"))
fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist"))
//http.Handle("/test", http.StripPrefix("/test", fs))
http.Handle("/", fs)
setupRootFileServer()

//setup handler //setup handler
//http.HandleFunc("/", webrootHandler) //http.HandleFunc("/", webrootHandler)
http.HandleFunc("/api", apiV1Main) http.HandleFunc("/api", apiV1Main)
http.HandleFunc("/crmfiles/", crmAttachmentHandler) http.HandleFunc("/crmfiles/", crmAttachmentHandler)
http.ListenAndServe(":65500", nil) 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)
}

Notiek ielāde…
Atcelt
Saglabāt