-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
125 lines (93 loc) · 3.38 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"fmt"
"flag"
"github.com/labstack/echo"
logger "EchoServer/logger"
"EchoServer/configs"
// . "github.com/0x19/goesl"
// "github.com/gorilla/mux"
"net/http"
"os"
// "runtime"
// "strings"
// "EchoServer/repository"
// adapters "EchoServer/adapters/repository"
)
type ContactDetails struct {
Email string
Subject string
Message string
}
var (
fshost = flag.String("fshost", "172.28.230.128", "Freeswitch hostname. Default: localhost")
fsport = flag.Uint("fsport", 8021, "Freeswitch port. Default: 8021")
password = flag.String("pass", "ClueCon", "Freeswitch password. Default: ClueCon")
timeout = flag.Int("timeout", 10, "Freeswitch conneciton timeout in seconds. Default: 10")
)
func handler(w http.ResponseWriter, r *http.Request) {
var name, _ = os.Hostname()
fmt.Fprintf(w, "<h1>This request was processed by host: %s</h1>\n", name)
}
func reloadxml(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPost {
return
}
var name, _ = os.Hostname()
fmt.Println("http.MethodPost : ",http.MethodPost);
fmt.Println("r.Method : ",r.Method);
fmt.Fprintf(w, "<h1>Reload Dialplan: %s</h1>\n", name)
}
func main(){
e := echo.New()
config := configs.GetConfig()
log := logger.NewLogger(config.Log.LogFile,config.Log.LogLevel)
fmt.Println("API Listener Application Started")
log1 := logger.NewLogger(config.Log.LogFile,config.Log.LogLevel);
// client, err := NewClient(*fshost, *fsport, *password, *timeout)
// if err != nil {
// Error("Error while creating new client: %s", err)
// return
// }
fmt.Fprintf(os.Stdout, "Web Server started. Listening on 0.0.0.0:2000\n")
// r := mux.NewRouter()
//
// r.HandleFunc("/EchoServer/hostname", handler).Schemes("http")
// r.HandleFunc("/EchoServer/reloadxml", reloadxml).Schemes("http")
http.HandleFunc("/EchoServer/hostname", handler)
http.HandleFunc("/EchoServer/reloadxml", reloadxml)
http.ListenAndServe(":2000", nil)
if err := e.Start("0.0.0.0:10000"); err != nil {
log.WithError(err).Fatal("echo server not able to start")
log1.WithError(err).Fatal("Welcome")
}
}
// func Get(uri string, timeout int, auth string, pass string, queryParam interface{}) (map[string]interface{}, int, error) {
// response := make(map[string]interface{})
// res, err := goreq.Request{
// Method: "GET",
// Uri: uri,
// ContentType: "application/json",
// Accept: "application/json",
// Timeout: time.Second * time.Duration(timeout),
// BasicAuthUsername: auth,
// BasicAuthPassword: pass,
// QueryString: queryParam,
// }.Do()
// return response, res.StatusCode, err
// }
//
// func Post(uri string, timeout int, auth string, pass string, queryParam interface{}) (map[string]interface{}, int, error) {
// response := make(map[string]interface{})
// res, err := goreq.Request{
// Method: "POST",
// Uri: uri,
// ContentType: "application/json",
// Accept: "application/json",
// Timeout: time.Second * time.Duration(timeout),
// BasicAuthUsername: auth,
// BasicAuthPassword: pass,
// Body: queryParam,
// }.Do()
// return response, res.StatusCode, err
// }