選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

54 行
1.3KB

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