twins/main.go

55 lines
1.3 KiB
Go
Raw Normal View History

2020-10-29 20:35:48 +00:00
package main
import (
"crypto/tls"
2020-10-29 20:35:48 +00:00
"flag"
"log"
"os"
"path"
)
2020-10-30 00:17:23 +00:00
func init() {
log.SetOutput(os.Stdout)
}
var verbose bool
2020-10-29 20:35:48 +00:00
func main() {
configFile := flag.String("config", "", "path to configuration file")
2020-10-30 00:17:23 +00:00
flag.BoolVar(&verbose, "verbose", false, "print request and response information")
2020-10-29 20:35:48 +00:00
flag.Parse()
if *configFile == "" {
homedir, err := os.UserHomeDir()
if err == nil && homedir != "" {
*configFile = path.Join(homedir, ".config", "twins", "config.yaml")
}
}
err := readconfig(*configFile)
if err != nil {
2020-10-29 20:35:48 +00:00
log.Fatalf("failed to read configuration file at %s: %v\nSee CONFIGURATION.md for information on configuring twins", *configFile, err)
}
if config.hostname == "" || config.port <= 0 {
log.Fatal("hostname and port must be specified")
2020-10-29 20:35:48 +00:00
}
if len(config.Certificates) == 0 {
log.Fatal("at least one certificate must be specified (gemini requires TLS for all connections)")
2020-10-29 20:35:48 +00:00
}
var certificates []tls.Certificate
for _, cert := range config.Certificates {
cert, err := tls.LoadX509KeyPair(cert.Cert, cert.Key)
if err != nil {
log.Fatalf("failed to load certificate: %s", err)
}
certificates = append(certificates, cert)
}
log.Printf("twins running on %s:%d", config.hostname, config.port)
listen(config.Listen, certificates)
2020-10-29 20:35:48 +00:00
}