/
docker_bip.go
43 lines (38 loc) · 916 Bytes
/
docker_bip.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
package main
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/spf13/cobra"
)
func init() {
http.HandleFunc("/"+API_VERSION+"/docker/bip", handleDockerBip)
cmds = append(cmds, &cobra.Command{
Use: "docker/bip [address]",
Short: "Get or Set Docker Bridge IP",
Long: "This gets or sets the IP for the internal docker bridge.",
Run: cmdDockerBip,
})
}
func cmdDockerBip(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println(MyAPIGet("docker/bip"))
} else if len(args) == 1 {
MyAPIPost("docker/bip", args[0])
} else {
cmd.HelpFunc()
}
}
func handleDockerBip(w http.ResponseWriter, r *http.Request) {
//w.Header().Add("Content-Type", "application/json")
if r.Method == "POST" {
body, _ := ioutil.ReadAll(r.Body)
config.Docker.Bip = string(body)
WriteDockerConfig()
RestartDocker()
saveConfig()
} else {
bip := config.Docker.Bip
w.Write([]byte(bip))
}
}