main.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "github.com/docopt/docopt-go"
  4. "os"
  5. "github.com/G-Node/gin-dex/gindex"
  6. "net/http"
  7. log "github.com/Sirupsen/logrus"
  8. )
  9. func main() {
  10. usage := `gin-dex.
  11. Usage:
  12. gin-dex [--eladress=<eladress> --eluser=<eluser> --elpw=<elpw> --rpath=<rpath> --gin=<gin> --port=<port> --debug ]
  13. Options:
  14. --eladress=<eladress> Adress of the elastic server [default: http://localhost:9200]
  15. --eluser=<eluser> Elastic user [default: elastic]
  16. --elpw=<elpw> Elastic password [default: changeme]
  17. --port=<port> Server port [default: 8099]
  18. --gin=<gin> Gin Server Adress [default: https://gin.g-node.org]
  19. --rpath=<rpath> Path to the repositories [default: /repos]
  20. --debug Whether debug messages shall be printed
  21. `
  22. args, err := docopt.Parse(usage, nil, true, "gin-dex0.1a", false)
  23. if err != nil {
  24. log.Printf("Error while parsing command line: %+v", err)
  25. os.Exit(-1)
  26. }
  27. uname := args["--eluser"].(string)
  28. pw := args["--elpw"].(string)
  29. els := gindex.NewElServer(args["--eladress"].(string), &uname, &pw)
  30. gin := &gindex.GinServer{URL: args["--gin"].(string)}
  31. rpath := args["--rpath"].(string)
  32. http.HandleFunc("/index", func(w http.ResponseWriter, r *http.Request) {
  33. gindex.IndexH(w, r, els, &rpath)
  34. })
  35. http.HandleFunc("/search", func(w http.ResponseWriter, r *http.Request) {
  36. gindex.SearchH(w, r, els, gin)
  37. })
  38. http.HandleFunc("/reindex", func(w http.ResponseWriter, r *http.Request) {
  39. gindex.ReindexH(w, r, els, gin, &rpath)
  40. })
  41. if args["--debug"].(bool) {
  42. log.SetLevel(log.DebugLevel)
  43. log.SetFormatter(&log.TextFormatter{ForceColors: true})
  44. }
  45. log.Fatal(http.ListenAndServe(":"+args["--port"].(string), nil))
  46. }