You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6KB

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "net/http/httputil"
  7. )
  8. //PathsConfig all system available pathes
  9. type PathsConfig struct {
  10. CRMAttachment string `json:"crm_attachmeng"`
  11. Angular2App string `json:"angular2_app"`
  12. }
  13. //GlobalPath all global pathes configurations
  14. var GlobalPath = PathsConfig{
  15. "/tmp/",
  16. "/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist/"}
  17. func main() {
  18. err := readConfig() //wechat API config
  19. if err != nil {
  20. log.Println(err)
  21. log.Fatal("unable to read server_config.json, program quit")
  22. return
  23. }
  24. err = readCRMConfig()
  25. if err != nil {
  26. log.Println(err)
  27. log.Fatal("unable to read crm_config.json, program quit")
  28. }
  29. setupRootFileServer()
  30. //setup handler
  31. //http.HandleFunc("/", webrootHandler)
  32. http.HandleFunc("/api", apiV1Main)
  33. http.HandleFunc("/upload", uploadHandler)
  34. http.HandleFunc("/crmfiles/", crmAttachmentHandler)
  35. http.HandleFunc("/dumprequest", dumpReuestHandler)
  36. http.ListenAndServe(":65500", nil)
  37. }
  38. func setupRootFileServer() {
  39. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  40. http.ServeFile(w, r, GlobalPath.Angular2App+r.URL.Path[1:])
  41. })
  42. //fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/ng2-admin/dist"))
  43. //http.Handle("/test", http.StripPrefix("/test", fs))
  44. //fs := http.FileServer(http.Dir("/mnt/data/workspace/angular.ts/wechat/ng2-admin/dist"))
  45. //http.Handle("/", fs)
  46. }
  47. func dumpReuestHandler(w http.ResponseWriter, r *http.Request) {
  48. logRequestDebug(httputil.DumpRequest(r, true))
  49. w.Header().Set("Content-Type", "application/json; charset=utf-8")
  50. w.Header().Set("Access-Control-Allow-Origin", "*")
  51. fmt.Fprintf(w, "{'status':'ok','msg':'done'}")
  52. }