1- package main
1+ package fetcher
22
33import (
44 "fmt"
@@ -18,19 +18,18 @@ const (
1818 cmdstring = "/tmp/builder/build.sh"
1919)
2020
21- func main () {
21+ // Serve will start the fetcher server and block until it stops. Since it blocks, it's a best practice to execute this func in a goroutine.
22+ func Serve (port int ) {
2223 rtr := mux .NewRouter ()
2324 rtr .HandleFunc ("/git/home/{name}/tar" , getTar ).Methods ("GET" )
2425 rtr .HandleFunc ("/git/home/{name}/slug" , getSlug ).Methods ("GET" )
2526 rtr .HandleFunc ("/git/home/health" , health ).Methods ("GET" )
2627 rtr .HandleFunc ("/git/home/{name}/push" , putSlug ).Methods ("PUT" )
27- http .Handle ("/" , rtr )
28- log .Println ("Listening... on 3000" )
29- http .ListenAndServe (":3000" , nil )
28+ hostStr := fmt .Sprintf (":%d" , port )
29+ http .ListenAndServe (hostStr , rtr )
3030}
3131
3232func getTar (w http.ResponseWriter , r * http.Request ) {
33- fmt .Println ("Hello, world! gettar" )
3433 params := mux .Vars (r )
3534 name := strings .Split (params ["name" ], ":" )[0 ]
3635 dat , err := ioutil .ReadFile (appdirectory + name + ".git/" + name + ".tar.gz" )
@@ -45,7 +44,6 @@ func health(w http.ResponseWriter, r *http.Request) {
4544}
4645
4746func getSlug (w http.ResponseWriter , r * http.Request ) {
48- fmt .Println ("Hello, world! getslug" )
4947 params := mux .Vars (r )
5048 name := params ["name" ]
5149 dat , err := ioutil .ReadFile (slugdirectory + name + "/slug.tgz" )
@@ -56,7 +54,6 @@ func getSlug(w http.ResponseWriter, r *http.Request) {
5654}
5755
5856func putSlug (w http.ResponseWriter , r * http.Request ) {
59- fmt .Println ("Hello, world! putslug" )
6057 params := mux .Vars (r )
6158 name := params ["name" ]
6259 log .Println (name )
0 commit comments