Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

48 lines
1010B

  1. package main
  2. import (
  3. "biukop.com/sfm/loan"
  4. "fmt"
  5. log "github.com/sirupsen/logrus"
  6. "net/http"
  7. )
  8. func main() {
  9. err := config.readConfig() //wechat API config
  10. if err != nil {
  11. log.Println(err)
  12. log.Fatalf("unable to read %s, program quit\n", configFile)
  13. return
  14. }
  15. setupRootFileServer()
  16. //always the last one
  17. setupHTTPHandler()
  18. }
  19. func setupRootFileServer() {
  20. //root of doc
  21. for idx, node := range config.Static {
  22. log.Printf("setting up %d static with %+v\n", idx, node)
  23. fs := http.FileServer(http.Dir(node.Dir))
  24. http.Handle(node.StaticUrl, http.StripPrefix(node.StripPrefix, fs))
  25. }
  26. }
  27. func setupHTTPHandler() {
  28. http.HandleFunc(apiV1Prefix, apiV1Main)
  29. http.HandleFunc("/dummy/", dummyHandler)
  30. log.Printf("Server started at %s:%s\n", config.Host, config.Port)
  31. log.Fatal(http.ListenAndServe(config.Host+":"+config.Port, nil))
  32. }
  33. func dummyHandler(w http.ResponseWriter, r *http.Request) {
  34. p := loan.People{}
  35. p.FakeNew()
  36. fmt.Fprintf(w, "Hello, there %s, %+v\n", loan.Version, p)
  37. }