代码拉取完成,页面将自动刷新
/*
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
"fmt"
"log"
"github.com/gofiber/fiber/v2"
"github.com/spf13/cobra"
)
// webCmd represents the web command
var webCmd = &cobra.Command{
Use: "web",
Short: "A powerful web app based on gofiber.",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
port, _ := cmd.Flags().GetInt("port")
serverIp, _ := cmd.Flags().GetString("ip")
app := fiber.New()
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
addr := fmt.Sprintf("%s:%d", serverIp, port)
log.Printf("The app is listen on %s.\n", addr)
log.Fatal(app.Listen(addr))
},
}
func init() {
rootCmd.AddCommand(webCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// webCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// webCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
webCmd.Flags().IntP("port", "p", 3000, "The port number that the server listens on.")
webCmd.Flags().StringP("ip", "i", "0.0.0.0", "The ip that the server listens on.")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。