This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (72 loc) · 2.31 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
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
)
// Flags parsed at program startup and never modified afterwards.
var configDir string
type Config struct {
ServerAddress string `json:"server_address"`
ServerURL string `json:"server_url"`
StaticDir string `json:"static_dir"`
EnableTLS bool `json:"enable_tls"`
TLSCertificate string `json:"tls_certificate"`
TLSPrivateKey string `json:"tls_private_key"`
EnableIDeal bool `json:"enable_ideal"`
IDealPathPrefix string `json:"ideal_path_prefix"`
IDealAcquirerCert string `json:"ideal_acquirer_cert"`
IDealMerchantCert string `json:"ideal_merchant_cert"`
IDealMerchantSk string `json:"ideal_merchant_sk"`
IDealCredentialID string `json:"ideal_credential_id"`
IDealBaseURL string `json:"ideal_base_url"`
IDealMerchantID string `json:"ideal_merchant_id"`
IDealSubID string `json:"ideal_sub_id"`
IrmaServerURL string `json:"irma_server_url"`
IrmaServerToken string `json:"irma_server_token"`
AuthenticationReturnURL string `json:"authentication_return_url"`
DonationReturnURL string `json:"donation_return_url"`
PaymentAmounts []string `json:"payment_amounts"`
AuthenticationPaymentMessage string `json:"authentication_payment_message"`
DonationPaymentMessage string `json:"donation_payment_message"`
}
var (
config Config
)
func readConfig() error {
data, err := readFile(configDir + "/config.json")
if err != nil {
return err
}
return json.Unmarshal(data, &config)
}
func main() {
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s <command> [args...]\n", os.Args[0])
fmt.Fprintln(flag.CommandLine.Output(), "Available commands: help, server")
fmt.Fprintln(flag.CommandLine.Output(), "Flags:")
flag.PrintDefaults()
}
flag.StringVar(&configDir, "config", "config", "Directory with configuration files")
flag.StringVar(&config.StaticDir, "static", config.StaticDir, "Static files to serve")
flag.Parse()
if flag.NArg() < 1 {
flag.Usage()
return
}
switch flag.Arg(0) {
case "help":
flag.Usage()
case "server":
err := readConfig()
if err != nil {
fmt.Fprintln(flag.CommandLine.Output(), "Could not read config file:", err)
return
}
cmdServe()
default:
fmt.Fprintln(flag.CommandLine.Output(), "Unknown command:", flag.Arg(0))
flag.Usage()
}
}