45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
)
|
|
|
|
func init() {
|
|
log.SetOutput(os.Stdout)
|
|
}
|
|
|
|
var verbose bool
|
|
|
|
func main() {
|
|
configFile := flag.String("config", "", "path to configuration file")
|
|
flag.BoolVar(&verbose, "verbose", false, "print request and response information")
|
|
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 {
|
|
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")
|
|
}
|
|
|
|
if config.Cert == "" || config.Key == "" {
|
|
log.Fatal("certificate file and private key must be specified (gemini requires TLS for all connections)")
|
|
}
|
|
|
|
log.Printf("twins running on port %d", config.Port)
|
|
|
|
listen(config.Hostname, config.Port, config.Cert, config.Key)
|
|
}
|