func main() { flag.Parse() glog.Infof("Starting Goship...") ctx := context.Background() ctx, cancel := context.WithCancel(ctx) defer cancel() auth.Initialize(auth.User{Name: *defaultUser, Avatar: *defaultAvatar}, []byte(*cookieSessionHash)) h, err := buildHandler(ctx) if err != nil { glog.Fatal(err) } w := io.WriteCloser(os.Stdout) if *requestLog != "-" { w, err = os.OpenFile(*requestLog, os.O_APPEND|os.O_CREATE, 0644) if err != nil { glog.Fatalf("Cannot open request log %s: %v", *requestLog, err) } defer w.Close() } h = ghandlers.CombinedLoggingHandler(w, h) fmt.Printf("Running on %s\n", *bindAddress) s := &http.Server{ Addr: *bindAddress, Handler: h, } if err := s.ListenAndServe(); err != nil { glog.Fatal(err) } }
func main() { flag.Parse() log.Printf("Starting Goship...") ctx := context.Background() ctx, cancel := context.WithCancel(ctx) defer cancel() auth.Initialize(auth.User{Name: *defaultUser, Avatar: *defaultAvatar}, []byte(*cookieSessionHash)) gcl, err := newGithubClient() if err != nil { log.Panicf("Failed to build github client: %v", err) } ac := acl.Null if auth.Enabled() { ac = acl.NewGithub(gcl) } if err := os.Mkdir(*dataPath, 0777); err != nil && !os.IsExist(err) { log.Fatal("could not create data dir: ", err) } hub := notification.NewHub(ctx) ecl := etcd.NewClient([]string{*ETCDServer}) assets := helpers.New(*staticFilePath) http.Handle("/", auth.Authenticate(HomeHandler{ac: ac, ecl: ecl, assets: assets})) http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, r.URL.Path[1:]) }) dph, err := deploypage.New(assets, fmt.Sprintf("ws://%s/web_push", *bindAddress)) if err != nil { log.Fatal(err) } http.Handle("/deploy", auth.Authenticate(dph)) http.Handle("/web_push", websocket.Handler(hub.AcceptConnection)) dlh := DeployLogHandler{assets: assets} http.Handle("/deployLog/", auth.AuthenticateFunc(extractDeployLogHandler(ac, ecl, dlh.ServeHTTP))) http.Handle("/output/", auth.AuthenticateFunc(extractOutputHandler(DeployOutputHandler))) pch := ProjCommitsHandler{ac: ac, gcl: gcl, ecl: ecl} http.Handle("/commits/", auth.AuthenticateFunc(extractCommitHandler(pch.ServeHTTP))) http.Handle("/deploy_handler", auth.Authenticate(DeployHandler{ecl: ecl, hub: hub})) http.Handle("/lock", auth.Authenticate(lock.NewLock(ecl))) http.Handle("/unlock", auth.Authenticate(lock.NewUnlock(ecl))) http.Handle("/comment", auth.Authenticate(comment.New(ecl))) http.HandleFunc("/auth/github/login", auth.LoginHandler) http.HandleFunc("/auth/github/callback", auth.CallbackHandler) fmt.Printf("Running on %s\n", *bindAddress) log.Fatal(http.ListenAndServe(*bindAddress, nil)) }