|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "html/template" |
| 5 | + "os" |
| 6 | + |
| 7 | + "github.com/brocaar/lora-gateway-bridge/internal/config" |
| 8 | + "github.com/pkg/errors" |
| 9 | + "github.com/spf13/cobra" |
| 10 | +) |
| 11 | + |
| 12 | +// when updating this template, don't forget to update config.md! |
| 13 | +const configTemplate = `[general] |
| 14 | +# debug=5, info=4, warning=3, error=2, fatal=1, panic=0 |
| 15 | +log_level = {{ .General.LogLevel }} |
| 16 | +
|
| 17 | +
|
| 18 | +# Configuration which relates to the packet-forwarder. |
| 19 | +[packet_forwarder] |
| 20 | +# ip:port to bind the UDP listener to |
| 21 | +# |
| 22 | +# Example: 0.0.0.0:1700 to listen on port 1700 for all network interfaces. |
| 23 | +# This is the listeren to which the packet-forwarder forwards its data |
| 24 | +# so make sure the 'serv_port_up' and 'serv_port_down' from your |
| 25 | +# packet-forwarder matches this port. |
| 26 | +udp_bind = "{{ .PacketForwarder.UDPBind }}" |
| 27 | +
|
| 28 | +# Skip the CRC status-check of received packets |
| 29 | +# |
| 30 | +# This is only has effect when the packet-forwarder is configured to forward |
| 31 | +# LoRa frames with CRC errors. |
| 32 | +skip_crc_check = {{ .PacketForwarder.SkipCRCCheck }} |
| 33 | +
|
| 34 | +
|
| 35 | +# Configuration for the MQTT backend. |
| 36 | +[backend.mqtt] |
| 37 | +# MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws) |
| 38 | +server="{{ .Backend.MQTT.Server }}" |
| 39 | +
|
| 40 | +# Connect with the given username (optional) |
| 41 | +username="{{ .Backend.MQTT.Username }}" |
| 42 | +
|
| 43 | +# Connect with the given password (optional) |
| 44 | +password="{{ .Backend.MQTT.Password }}" |
| 45 | +
|
| 46 | +# CA certificate file (optional) |
| 47 | +# |
| 48 | +# Use this when setting up a secure connection (when server uses ssl://...) |
| 49 | +# but the certificate used by the server is not trusted by any CA certificate |
| 50 | +# on the server (e.g. when self generated). |
| 51 | +ca_cert="{{ .Backend.MQTT.CACert }}" |
| 52 | +
|
| 53 | +# mqtt TLS certificate file (optional) |
| 54 | +tls_cert="{{ .Backend.MQTT.TLSCert }}" |
| 55 | +
|
| 56 | +# mqtt TLS key file (optional) |
| 57 | +tls_key="{{ .Backend.MQTT.TLSKey }}" |
| 58 | +` |
| 59 | + |
| 60 | +var configCmd = &cobra.Command{ |
| 61 | + Use: "configfile", |
| 62 | + Short: "Print the LoRa Gateway Bridge configuration file", |
| 63 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 64 | + t := template.Must(template.New("config").Parse(configTemplate)) |
| 65 | + err := t.Execute(os.Stdout, config.C) |
| 66 | + if err != nil { |
| 67 | + return errors.Wrap(err, "execute config template error") |
| 68 | + } |
| 69 | + return nil |
| 70 | + }, |
| 71 | +} |
0 commit comments