/
orbiter.go
100 lines (85 loc) · 2.77 KB
/
orbiter.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
// Copyright 2016 Unknwon
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
// Orbiter is a tool for collecting and redistributing webhooks over the network.
package main
import (
"fmt"
"net/http"
"github.com/flamego/auth"
"github.com/flamego/binding"
"github.com/flamego/flamego"
"github.com/flamego/template"
log "unknwon.dev/clog/v2"
"unknwon.dev/orbiter/internal/route"
apiv1 "unknwon.dev/orbiter/internal/route/api/v1"
"unknwon.dev/orbiter/internal/setting"
"unknwon.dev/orbiter/internal/templateutil"
)
func main() {
if err := log.NewConsole(); err != nil {
panic("error init logger: " + err.Error())
}
defer log.Stop()
log.Info("Orbiter: %s", setting.Version)
f := flamego.Classic()
f.Use(template.Templater(
template.Options{
FuncMaps: templateutil.NewFuncMap(),
},
))
f.Group("",
func() {
f.Get("/", route.Dashboard)
f.Group("/collectors", func() {
f.Get("", route.Collectors)
f.Combo("/new").
Get(route.NewCollector).
Post(binding.Form(route.NewCollectorForm{}), route.NewCollectorPost)
f.Group("/{id}", func() {
f.Combo("").
Get(route.EditCollector).
Post(binding.Form(route.NewCollectorForm{}), route.EditCollectorPost)
f.Post("/regenerate_token", route.RegenerateCollectorSecret)
f.Post("/delete", route.DeleteCollector)
})
})
f.Group("/applications", func() {
f.Get("", route.Applications)
f.Combo("/new").
Get(route.NewApplication).
Post(binding.Form(route.NewApplicationForm{}), route.NewApplicationPost)
f.Group("/{id}", func() {
f.Combo("").
Get(route.EditApplication).
Post(binding.Form(route.NewApplicationForm{}), route.EditApplicationPost)
f.Post("/regenerate_token", route.RegenerateApplicationSecret)
f.Post("/delete", route.DeleteApplication)
})
})
f.Group("/webhooks", func() {
f.Get("", route.Webhooks)
f.Get("/{id}", route.ViewWebhook)
})
f.Get("/config", route.Config)
},
auth.Basic(setting.BasicAuth.User, setting.BasicAuth.Password),
)
f.Post("/hook", route.Hook)
f.Group("/api", func() {
apiv1.RegisterRoutes(f)
})
listenAddr := fmt.Sprintf("0.0.0.0:%d", setting.HTTPPort)
log.Info("Listening on http://%s...", listenAddr)
log.Fatal("Failed to start server: %v", http.ListenAndServe(listenAddr, f))
}