1 Star 0 Fork 0

Arthur/redoron

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
web.go 2.03 KB
一键复制 编辑 原始数据 按行查看 历史
Arthur 提交于 2年前 . bugfix: stock
/*
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.")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/palagend/redoron.git
git@gitee.com:palagend/redoron.git
palagend
redoron
redoron
master

搜索帮助