-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfetcher.go
More file actions
76 lines (68 loc) · 1.71 KB
/
fetcher.go
File metadata and controls
76 lines (68 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"github.com/gorilla/mux"
)
const (
appdirectory = "/home/git/"
slugdirectory = "/apps/"
cmdstring = "/tmp/builder/build.sh"
)
func main() {
rtr := mux.NewRouter()
rtr.HandleFunc("/git/home/{name}/tar", getTar).Methods("GET")
rtr.HandleFunc("/git/home/{name}/slug", getSlug).Methods("GET")
rtr.HandleFunc("/git/home/health", health).Methods("GET")
rtr.HandleFunc("/git/home/{name}/push", putSlug).Methods("PUT")
http.Handle("/", rtr)
log.Println("Listening... on 3000")
http.ListenAndServe(":3000", nil)
}
func getTar(w http.ResponseWriter, r *http.Request) {
fmt.Println("Hello, world! gettar")
params := mux.Vars(r)
name := strings.Split(params["name"], ":")[0]
dat, err := ioutil.ReadFile(appdirectory + name + ".git/" + name + ".tar.gz")
if err != nil {
w.Write([]byte(name + "dosn't exist"))
}
w.Write(dat)
}
func health(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, world!")
}
func getSlug(w http.ResponseWriter, r *http.Request) {
fmt.Println("Hello, world! getslug")
params := mux.Vars(r)
name := params["name"]
dat, err := ioutil.ReadFile(slugdirectory + name + "/slug.tgz")
if err != nil {
w.Write([]byte(name + "dosn't exist"))
}
w.Write(dat)
}
func putSlug(w http.ResponseWriter, r *http.Request) {
fmt.Println("Hello, world! putslug")
params := mux.Vars(r)
name := params["name"]
log.Println(name)
err := os.MkdirAll(slugdirectory+name, 0755)
if err != nil {
fmt.Println(err)
}
output, err := os.Create(slugdirectory + name + "/slug.tgz")
if err != nil {
fmt.Println(err)
}
defer output.Close()
defer r.Body.Close()
fmt.Println(r.ContentLength)
io.Copy(output, r.Body)
return
}