-
Notifications
You must be signed in to change notification settings - Fork 10
/
api_utils.go
57 lines (47 loc) · 1.11 KB
/
api_utils.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"os"
)
func FindAllDir(targetPath string) ([]os.FileInfo, bool) {
var list []os.FileInfo
var err error
if list, err = ioutil.ReadDir(targetPath); err != nil {
log.Println("Error finding repository:", err)
return nil, false
}
return list, true
}
func FormCloneURL(host, userName, repoName string) string {
return (fmt.Sprintf(GetProtocol(config.SSLEnabled) + host + "/" + userName + "/" + repoName))
}
func GetRepoCreateURL() string {
return "/api/repos/create"
}
func GetReposURL() string {
return "/api/{user-name}/repos"
}
func GetRepoURL() string {
return "/api/{user-name}/repos/{repo-name}"
}
func GetBranchesURL() string {
return "/api/{user-name}/repos/{repo-name}/branches"
}
func GetBranchURL() string {
return "/api/{user-name}/repos/{repo-name}/branches/{branch-name}"
}
func GetProtocol(ssl bool) string {
if ssl {
return "https://"
}
return "http://"
}
func WriteIndentedJSON(w io.Writer, v interface{}, prefix, indent string) {
resp, _ := json.MarshalIndent(v, prefix, indent)
w.Write(resp)
w.Write([]byte("\n"))
}