-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
server.go
56 lines (47 loc) · 1.32 KB
/
server.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
package api
import (
"net"
"net/http"
"strconv"
"github.com/gorilla/mux"
ddconfig "github.com/DataDog/datadog-agent/pkg/config"
settingshttp "github.com/DataDog/datadog-agent/pkg/config/settings/http"
"github.com/DataDog/datadog-agent/pkg/util/log"
)
func setupHandlers(r *mux.Router) {
r.HandleFunc("/config", settingshttp.Server.GetFull("process_config")).Methods("GET")
r.HandleFunc("/config/list-runtime", settingshttp.Server.ListConfigurable).Methods("GET")
r.HandleFunc("/config/{setting}", settingshttp.Server.GetValue).Methods("GET")
r.HandleFunc("/config/{setting}", settingshttp.Server.SetValue).Methods("POST")
}
// StartServer starts the config server
func StartServer() error {
// Set up routes
r := mux.NewRouter()
setupHandlers(r)
addr, err := getIPCAddressPort()
if err != nil {
return err
}
log.Infof("API server listening on %s", addr)
srv := &http.Server{
Handler: r,
Addr: addr,
}
go func() {
err := srv.ListenAndServe()
if err != nil {
_ = log.Error(err)
}
}()
return nil
}
// getIPCAddressPort returns a listening connection
func getIPCAddressPort() (string, error) {
address, err := ddconfig.GetIPCAddress()
if err != nil {
return "", err
}
addrPort := net.JoinHostPort(address, strconv.Itoa(ddconfig.Datadog.GetInt("process_config.cmd_port")))
return addrPort, nil
}