Skip to content

Commit

Permalink
fix:修改默认模板
Browse files Browse the repository at this point in the history
  • Loading branch information
zwtesttt committed May 20, 2024
1 parent 123d50b commit 7a5ca16
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/

test/*
test/*
./build
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GO := go
APP_NAME := coss-cli

# 版本号
VERSION := 1.0.0
VERSION := 1.0.1

# 交叉编译目标平台
PLATFORMS := linux windows darwin
Expand All @@ -25,7 +25,7 @@ LDFLAGS := -ldflags "-s -w -X main.version=$(VERSION)"
# 构建目标
.PHONY: build
build:
@$(GO) build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-$(GOOS)-$(GOARCH)-$(VERSION)$(EXT)
@$(GO) build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-$(VERSION)$(EXT)

# 打包目标
.PHONY: package
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ coss-cli gen --direct=false
docker-compose up -d
coss-cli config --path ./config/common --namespace common
coss-cli config --path ./config/service --namespace service
coss-cli route --direct=false --route-host=192.168.100.236
coss-cli route --direct=false --route-host=<your-consul-host>
```
>如果要指定consul地址,可以使用`--host`参数,默认为`http://127.0.0.1:8500`
>
Expand Down
11 changes: 3 additions & 8 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/urfave/cli/v2"
)

const VERSION = "v1.0.0"
const VERSION = "v1.0.1"

var App = &cli.App{
Name: "coss-cli",
Expand Down Expand Up @@ -60,14 +60,9 @@ var App = &cli.App{
Value: "./",
Usage: "config path",
},
&cli.StringFlag{
Name: "env",
Value: "dev",
Usage: "dev or prod",
},
&cli.StringFlag{
Name: "domain",
Value: "tuo.gezi.vip",
Value: "127.0.0.1",
Usage: "your domain name",
},
&cli.BoolFlag{
Expand All @@ -76,7 +71,7 @@ var App = &cli.App{
Usage: "consul enable ssl",
},
},
Action: genFile,
Action: gen,
},
{
Name: "route",
Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions cmd/file.go → cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (
"path/filepath"
)

func genFile(cCtx *cli.Context) error {
func gen(cCtx *cli.Context) error {
direct := cCtx.Bool("direct")
outputDir := cCtx.String("path")
env := cCtx.String("env")
domain := cCtx.String("domain")
enableSsl := cCtx.Bool("ssl")
cacheDir := "./config"
Expand Down Expand Up @@ -50,7 +49,7 @@ func genFile(cCtx *cli.Context) error {
httpport := config.HttpPort[httpname]
grpcport := config.GrpcPort[grpcname]

configStr := config.GenServiceConfig(httpname, grpcname, httpport, grpcport, env, enableSsl, domain)
configStr := config.GenServiceConfig(httpname, grpcname, httpport, grpcport, enableSsl, domain)
filePath := filepath.Join(outputDir+"/config/service/", fmt.Sprintf("%s.yaml", name))
err := ioutil.WriteFile(filePath, []byte(configStr), 0644)
if err != nil {
Expand All @@ -71,7 +70,7 @@ func genFile(cCtx *cli.Context) error {
httpport := config.HttpPort[httpname]
grpcport := config.GrpcPort[grpcname]

configStr := config.GenConsulServiceConfig(httpname, grpcname, httpport, grpcport, env, enableSsl, domain)
configStr := config.GenConsulServiceConfig(httpname, grpcname, httpport, grpcport, enableSsl, domain)
filePath := filepath.Join(outputDir+"/config/service/", fmt.Sprintf("%s.yaml", name))
err := ioutil.WriteFile(filePath, []byte(configStr), 0644)
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions cmd/route.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"fmt"
"github.com/cossim/coss-cli/pkg/apisix"
"github.com/urfave/cli/v2"
)

func initRoute(context *cli.Context) error {
apiKey := context.String("key")
host := context.String("host")
direct := context.Bool("direct")
domain := context.String("domain")
livekitDomain := context.String("livekit")
routeHost := context.String("route-host")

baseURL := host + "/apisix/admin/routes/"

client := apisix.NewApiClient(apiKey, baseURL)

route := client.GetRoutes(domain, routeHost, livekitDomain, direct)

for i, r := range route {
resp, err := client.SendRequest("PUT", fmt.Sprintf("%d", i+1), r)
if err != nil {
fmt.Printf("Error sending request for route %d: %v\n", i+1, err)
continue
}
fmt.Printf("Route %d created successfully: %s\n", i+1, resp)
}
return nil
}
25 changes: 0 additions & 25 deletions cmd/apisix.go → cmd/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,6 @@ import (
"io/ioutil"
)

func initRoute(context *cli.Context) error {
apiKey := context.String("key")
host := context.String("host")
direct := context.Bool("direct")
domain := context.String("domain")
livekitDomain := context.String("livekit")
routeHost := context.String("route-host")

baseURL := host + "/apisix/admin/routes/"

client := apisix.NewApiClient(apiKey, baseURL)

route := client.GetRoutes(domain, routeHost, livekitDomain, direct)

for i, route := range route {
resp, err := client.SendRequest("PUT", fmt.Sprintf("%d", i+1), route)
if err != nil {
fmt.Printf("Error sending request for route %d: %v\n", i+1, err)
continue
}
fmt.Printf("Route %d created successfully: %s\n", i+1, resp)
}
return nil
}

func uploadSSL(context *cli.Context) error {
certPath := context.String("cert")
keyPath := context.String("private_key")
Expand Down
15 changes: 5 additions & 10 deletions config/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package config

import "fmt"

func GenServiceConfig(httpName string, grpcName string, httpPort string, grpcPort string, env string, enableSsl bool, domain string) string {
func GenServiceConfig(httpName string, grpcName string, httpPort string, grpcPort string, enableSsl bool, domain string) string {
return fmt.Sprintf(`
system:
environment: "%s" # dev、prod
ssl: %t # 是否启用ssl true的话不会使用port
gateway_address: "%s"
gateway_port: 8080
gateway_address_dev: "127.0.0.1"
gateway_port_dev: 8080
log:
stdout: true
Expand Down Expand Up @@ -139,18 +136,16 @@ oss:
presignedExpires: ""
dial: "3000ms"
timeout: "5000ms"
`, env, enableSsl, domain, httpPort, grpcPort, grpcName, grpcName)
`, enableSsl, domain, httpPort, grpcPort, grpcName, grpcName)
}

func GenConsulServiceConfig(httpName, grpcName, httpPort, grpcPort string, env string, enableSsl bool, domain string) string {
func GenConsulServiceConfig(httpName, grpcName, httpPort, grpcPort string, enableSsl bool, domain string) string {
return fmt.Sprintf(`
system:
environment: "%s" # dev、prod
ssl: %t # 是否启用ssl true的话不会使用port
gateway_address: "%s"
gateway_port: 8080
gateway_address_dev: "127.0.0.1"
gateway_port_dev: 8080
jwt_secret: "secret"
log:
stdout: true
Expand Down Expand Up @@ -225,5 +220,5 @@ encryption:
multiple_device_limit:
enable: false
max: 1
`, env, enableSsl, domain, httpName, httpPort, grpcName, grpcPort, grpcName, grpcName)
`, enableSsl, domain, httpName, httpPort, grpcName, grpcPort, grpcName, grpcName)
}

0 comments on commit 7a5ca16

Please sign in to comment.