new

package
v0.0.0-...-e5591e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "new",
	Short: "创建 sniper 项目",
	Long:  `默认包名为 sniper`,
	Run: func(cmd *cobra.Command, args []string) {
		color.White(strings.TrimLeft(`
███████ ███    ██ ██ ██████  ███████ ██████  
██      ████   ██ ██ ██   ██ ██      ██   ██ 
███████ ██ ██  ██ ██ ██████  █████   ██████  
     ██ ██  ██ ██ ██ ██      ██      ██   ██ 
███████ ██   ████ ██ ██      ███████ ██   ██ 
https://github.com/go-kiss/sniper
`, "\n"))

		fail := false
		if err := exec.Command("git", "--version").Run(); err != nil {
			color.Red("git is not found")
			fail = true
		}

		if err := exec.Command("make", "--version").Run(); err != nil {
			color.Red("make is not found")
			fail = true
		}

		if err := exec.Command("protoc", "--version").Run(); err != nil {
			color.Red("protoc is not found")
			fail = true
		}

		if fail {
			os.Exit(110)
		}

		run("go", "install", "google.golang.org/protobuf/cmd/protoc-gen-go@latest")

		parts := strings.Split(pkg, "/")
		path := parts[len(parts)-1]
		run("git", "clone", "https://github.com/go-kiss/sniper.git",
			"--quiet", "--depth=1", "--branch="+branch, path)

		if err := os.Chdir(path); err != nil {
			panic(err)
		}

		if pkg == "sniper" {
			return
		}

		color.Cyan("rename sniper to " + pkg)
		replace("go.mod", "module sniper", "module "+pkg, 1)
		for _, p := range []string{"main.go", "cmd/http/http.go"} {
			replace(p, `"sniper`, `"`+pkg, -1)
		}

		color.Cyan("register foo service")
		run("sniper", "rpc", "--server=foo", "--version=1", "--service=bar")

		color.Cyan("you can run service by")
		color.Yellow("CONF_PATH=`pwd` go run main.go http")
		color.Cyan("you can use the httpie to call api by")
		color.Yellow("http :8080/api/foo.v1.Bar/Echo msg=hello")
	},
}

Cmd 项目初始化工具

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL