-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (41 loc) · 1.08 KB
/
main.go
File metadata and controls
52 lines (41 loc) · 1.08 KB
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
package main
import (
"context"
"encoding/json"
"fmt"
commonHttp "github.com/kulycloud/common/http"
"github.com/kulycloud/common/logging"
)
var logger = logging.GetForComponent("service")
func main() {
srv, err := commonHttp.NewServer(30000, echoHandler)
if err != nil {
logger.Panicw("could not create server", "error", err)
}
err = srv.Serve()
if err != nil {
logger.Panicw("could not serve", "error", err)
}
}
type config struct {
Data string `json:"data"`
ContentType *string `json:"contentType,omitempty"`
}
func echoHandler(_ context.Context, request *commonHttp.Request) *commonHttp.Response {
conf := &config{}
err := json.Unmarshal([]byte(request.KulyData.Step.Config), conf)
resp := commonHttp.NewResponse()
if err != nil {
resp.Status = 500
resp.Body.Write([]byte(fmt.Sprintf("Invalid config specified: %s", err.Error())))
return resp
}
if conf.ContentType != nil {
resp.Headers.Set("Content-Type", *conf.ContentType)
} else {
resp.Headers.Set("Content-Type", "text/plain")
}
resp.Status = 200
resp.Body.Write([]byte(conf.Data))
return resp
}