-
Notifications
You must be signed in to change notification settings - Fork 1
/
formrecevr.go
64 lines (52 loc) · 1.45 KB
/
formrecevr.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
package main
import (
"fmt"
"log"
"os"
"github.com/dorianim/formrecevr/internal/config"
"github.com/dorianim/formrecevr/internal/server"
"github.com/dorianim/formrecevr/internal/template"
"github.com/gin-gonic/gin"
"github.com/spf13/cobra"
)
var rootCmd = NewRootCommand()
// NewRootCommand creates the root command for watchtower
func NewRootCommand() *cobra.Command {
return &cobra.Command{
Use: "formrecevr",
Short: "Receives form data via an http API and forwards them",
Long: `
Formrecevr receives form data via an http API and forwards them using shoutrrr
More information is available at: https://github.com/dorianim/formrecevr
`,
Run: Run,
PreRun: PreRun,
}
}
func main() {
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
}
// PreRun is currently unused
func PreRun(cmd *cobra.Command, _ []string) {
}
// Run starts the server
func Run(c *cobra.Command, names []string) {
gin.SetMode(gin.ReleaseMode)
configPath, isSet := os.LookupEnv("FORMRECEVR_CONFIG_PATH")
if !isSet {
configPath = "/config"
}
if err := config.Setup(configPath); err != nil {
log.Fatalf("Error in config setup: %v", err)
}
templatePath := fmt.Sprintf("%s/templates", config.PathUsed())
template.Setup(templatePath)
if err := template.CreateDefaultTemplate(); err != nil {
log.Fatalf("Error creating default template: %v", err)
}
server.Setup()
err := server.ListenAndServe()
log.Fatalf("http: web server closed unexpect: %s", err)
}