mirror of
https://github.com/davidallendj/configurator.git
synced 2025-12-20 03:27:02 -07:00
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
//go:build server || all
|
|
// +build server all
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/OpenCHAMI/configurator/internal/server"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var serveCmd = &cobra.Command{
|
|
Use: "serve",
|
|
Short: "Start configurator as a server and listen for requests",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
// set up the routes and start the server
|
|
server := server.New()
|
|
err := server.Start(&config)
|
|
if errors.Is(err, http.ErrServerClosed) {
|
|
fmt.Printf("Server closed.")
|
|
} else if err != nil {
|
|
logrus.Errorf("failed to start server: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
serveCmd.Flags().StringVar(&config.Server.Host, "host", config.Server.Host, "set the server host")
|
|
serveCmd.Flags().IntVar(&config.Server.Port, "port", config.Server.Port, "set the server port")
|
|
serveCmd.Flags().StringVar(&config.Options.JwksUri, "jwks-uri", config.Options.JwksUri, "set the JWKS url to fetch public key")
|
|
serveCmd.Flags().IntVar(&config.Options.JwksRetries, "jwks-fetch-retries", config.Options.JwksRetries, "set the JWKS fetch retry count")
|
|
rootCmd.AddCommand(serveCmd)
|
|
}
|