package main
import (
"net/http"
"log"
)func main() {
// this calls loadConfig in util.go.
// I might put util.go in another package in the near future
LoadConfig()
// this calls service.go's route to handle the routing.
Route()
// Start the server on port 8888
err := http.ListenAndServe(":8888", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}Main
{"repositories":[
{"name":"testrepo", "path":"/home/j/src/git-sandbox", "scm":"git"}
]
}config.json
| Git Repository | |
|---|---|
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os/exec" |
| 5 | "fmt" |
| 6 | ) |
| 7 | |
| 8 | type GitRepository struct { |
| 9 | RepositoryInfo |
| 10 | } |
| 11 | |
| 12 | func (repo *GitRepository) GetName() string { |
| 13 | return repo.Name |
| 14 | } |
| 15 | |
| 16 | func (repo *GitRepository) GetPath() string { |
| 17 | return repo.Path |
| 18 | } |
| 19 | |
| 20 | // GetFile implementation - returns the file bytes |
| 21 | // after executing cd /path/to/repo ; git show sha |
| 22 | // This cmd is returning an empty byte[] for me atm, need to investigate later |
| 23 | func (repo *GitRepository) GetFile(id string) []byte { |
| 24 | out, _ := exec.Command("cd", repo.Path, ";", "git", "show", id).Output() |
| 25 | fmt.Println(out) |
| 26 | return out |
| 27 | } |
| 28 | |
| 29 | // GetFileExists implementation - returns true if the file exists |
| 30 | // after executing cd /path/to/repo ; git show sha |
| 31 | func (repo *GitRepository) GetFileExists(id string) bool { |
| 32 | cmd := exec.Command("cd", repo.Path, ";", "git", "show", id) |
| 33 | return cmd.Run() == nil |
| 34 | } |