rebound/cmd/server/main.go

62 lines
1.4 KiB
Go

package main
import (
"flag"
"log"
"os"
"os/signal"
"forge.cadoles.com/wpetit/rebound"
"forge.cadoles.com/wpetit/rebound/http"
"forge.cadoles.com/wpetit/rebound/ssh"
"github.com/pkg/errors"
)
func main() {
opts := rebound.DefaultOptions()
if err := opts.ParseEnv(); err != nil {
log.Fatalf("[ERROR] %+v", errors.WithStack(err))
}
// Global Options
address := flag.String("address", opts.Address, "server listening address")
// SSH Options
sockDir := flag.String("ssh-sock-dir", opts.SSH.SockDir, "ssh sock directory")
publicPort := flag.Uint("ssh-public-port", opts.SSH.PublicPort, "ssh public port")
publicHost := flag.String("ssh-public-host", opts.SSH.PublicHost, "ssh public host")
hostKey := flag.String("ssh-host-key", opts.SSH.HostKey, "ssh host key")
// HTTP Options
customDir := flag.String("http-custom-dir", opts.HTTP.CustomDir, "http custom templates/assets directory")
flag.Parse()
server := rebound.NewServer(
rebound.WithAddress(*address),
rebound.WithSSHOption(
ssh.WithSockDir(*sockDir),
ssh.WithPublicHost(*publicHost),
ssh.WithPublicPort(*publicPort),
ssh.WithHostKey(*hostKey),
),
rebound.WitHTTPOption(
http.WithCustomDir(*customDir),
),
)
if err := server.Start(); err != nil {
log.Fatalf("[FATAL] %+v", errors.WithStack(err))
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
if err := server.Stop(); err != nil {
log.Fatalf("[FATAL] %+v", errors.WithStack(err))
}
}