rebound/cmd/server/main.go

62 lines
1.4 KiB
Go
Raw Normal View History

2023-09-09 04:00:00 +02:00
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"
2023-09-09 04:00:00 +02:00
"github.com/pkg/errors"
)
func main() {
opts := rebound.DefaultOptions()
if err := opts.ParseEnv(); err != nil {
2023-09-09 04:00:00 +02:00
log.Fatalf("[ERROR] %+v", errors.WithStack(err))
}
// Global Options
2023-09-09 04:00:00 +02:00
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")
2023-09-09 04:00:00 +02:00
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),
),
2023-09-09 04:00:00 +02:00
)
if err := server.Start(); err != nil {
log.Fatalf("[FATAL] %+v", errors.WithStack(err))
}
2023-09-09 04:00:00 +02:00
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))
}
}