-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (37 loc) · 905 Bytes
/
main.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
package main
import (
"deploy-ci/ansible"
"fmt"
"log"
"net/http"
"os"
)
func main() {
if len(os.Args) != 4 {
fmt.Println("Please specify the port, ansible playbook and user to use in ansible execution")
fmt.Println("e.g: deploy-ci 3000 test.yml arthur")
os.Exit(1)
}
port := os.Args[1]
route := http.NewServeMux()
route.HandleFunc("/", RequestHandler)
err := http.ListenAndServe(fmt.Sprintf(":%s", port), route)
if err != nil {
log.Fatal(err)
}
}
// RequestHandler handes all requests that come in to the application via HTTP calls.
func RequestHandler(w http.ResponseWriter, r *http.Request) {
var playbook string = os.Args[2]
var user string = os.Args[3]
if playbook == "" && user == "" {
err := ansible.Run("test.yml", "arthur")
if err != nil {
fmt.Fprint(w, err.Error())
}
}
err := ansible.Run(playbook, user)
if err != nil {
fmt.Fprint(w, err.Error())
}
}