コミット
66949765d1
|
@ -6,15 +6,22 @@ import (
|
||||||
"codeberg.org/gothub/gothub/serve"
|
"codeberg.org/gothub/gothub/serve"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var port string = "3000"
|
||||||
|
|
||||||
var serveCmd = &cobra.Command{
|
var serveCmd = &cobra.Command{
|
||||||
Use: "serve",
|
Use: "serve",
|
||||||
Short: "Start the web server.",
|
Short: "Start the web server.",
|
||||||
Long: `Start the web server.`,
|
Long: `Start the web server.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
serve.Serve()
|
serve.Serve(port)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(serveCmd)
|
rootCmd.AddCommand(serveCmd)
|
||||||
|
|
||||||
|
serveCmd.Flags().StringVarP(&port, "port", "p", "", "The port GotHub will listen to. Defaults to 3000, and overrides the GOTHUB_PORT environment variable.")
|
||||||
|
|
||||||
|
// set port variable to the value of the port flag
|
||||||
|
port = serveCmd.Flag("port").Value.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Serve() {
|
func Serve(port string) {
|
||||||
engine := html.New("./views", ".html")
|
engine := html.New("./views", ".html")
|
||||||
|
|
||||||
engine.AddFunc(
|
engine.AddFunc(
|
||||||
|
@ -135,5 +135,8 @@ func Serve() {
|
||||||
if !ok {
|
if !ok {
|
||||||
val = "3000"
|
val = "3000"
|
||||||
}
|
}
|
||||||
|
if port != "" {
|
||||||
|
val = port
|
||||||
|
}
|
||||||
log.Fatal(app.Listen(":" + val))
|
log.Fatal(app.Listen(":" + val))
|
||||||
}
|
}
|
||||||
|
|
読み込み中…
新しいイシューから参照