-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.go
41 lines (35 loc) · 1.31 KB
/
server.go
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
package main
import (
"fmt"
"github.com/gorilla/mux"
"log"
"net/http"
)
func GitServer() {
host := fmt.Sprintf("%s:%s", config.Hostname, config.Port)
log.Println("Starting git http server at", host)
r := mux.NewRouter()
attachHandler(r)
if config.SSLEnabled {
if err := http.ListenAndServeTLS(host, "server.pem", "server.key", r); err != nil {
log.Fatal(err)
}
} else {
if err := http.ListenAndServe(host, r); err != nil {
log.Fatal(err)
}
}
}
func attachHandler(r *mux.Router) {
//git methods Handler
r.HandleFunc(`/{user-name}/{repo-name:([a-zA-Z0-9\-\.\_]+)}/info/refs`, basicAuthentication(serviceHandler)).Methods("GET")
r.HandleFunc(`/{user-name}/{repo-name:([a-zA-Z0-9\-\.\_]+)}/git-upload-pack`, basicAuthentication(uploadPackHandler)).Methods("POST")
r.HandleFunc(`/{user-name}/{repo-name:([a-zA-Z0-9\-\.\_]+)}/git-receive-pack`, basicAuthentication(receivePackHandler)).Methods("POST")
//APIs handlers
r.HandleFunc("/", rootHandler).Methods("GET")
r.HandleFunc(GetRepoCreateURL(), basicAuthentication(repoCreateHandler)).Methods("POST")
r.HandleFunc(GetReposURL(), repoIndexHandler).Methods("GET")
r.HandleFunc(GetRepoURL(), repoShowHandler).Methods("GET")
r.HandleFunc(GetBranchesURL(), branchIndexHandler).Methods("GET")
r.HandleFunc(GetBranchURL(), branchShowHandler).Methods("GET")
}