A simple page for all your links.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

65 wiersze
1.2 KiB

  1. package publicbio
  2. import (
  3. "encoding/json"
  4. "flag"
  5. "fmt"
  6. "github.com/gorilla/mux"
  7. "github.com/gorilla/schema"
  8. "github.com/writeas/web-core/converter"
  9. "io/ioutil"
  10. "log"
  11. "net/http"
  12. )
  13. type app struct {
  14. router *mux.Router
  15. cfg *config
  16. singleUser *Profile
  17. }
  18. func (app *app) multiUser() bool {
  19. return app.singleUser == nil
  20. }
  21. type config struct {
  22. host string
  23. port int
  24. }
  25. func Serve() {
  26. app := &app{
  27. cfg: &config{},
  28. }
  29. flag.IntVar(&app.cfg.port, "p", 8080, "Port to start server on")
  30. flag.StringVar(&app.cfg.host, "h", "https://public.bio", "Site's base URL")
  31. var userFile string
  32. flag.StringVar(&userFile, "u", "", "Configuration file for single-user site")
  33. flag.Parse()
  34. if userFile != "" {
  35. f, err := ioutil.ReadFile(userFile)
  36. if err != nil {
  37. log.Fatal("File error: %v\n", err)
  38. }
  39. json.Unmarshal(f, &app.singleUser)
  40. fmt.Printf("Results: %v\n", app.singleUser)
  41. } else {
  42. log.Fatal("No user configuration")
  43. }
  44. initRoutes(app)
  45. http.Handle("/", app.router)
  46. log.Printf("Serving on localhost:%d", app.cfg.port)
  47. http.ListenAndServe(fmt.Sprintf(":%d", app.cfg.port), nil)
  48. }
  49. func initConverter() {
  50. formDecoder := schema.NewDecoder()
  51. formDecoder.RegisterConverter(converter.NullJSONString{}, converter.JSONNullString)
  52. }