Skip to content

Commit

Permalink
feat: add version subcommand (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Han-Ya-Jun authored Jun 6, 2023
1 parent b8b028d commit 412259c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cov:

.PHONY: build
build:
go build -o bk-apigateway-core-api
go build -ldflags "-X core/pkg/version.Version=${VERSION} -X core/pkg/version.Commit=`git rev-parse HEAD` -X core/pkg/version.BuildTime=`date +%Y-%m-%d_%I:%M:%S` -X 'core/pkg/version.GoVersion=`go version`'" -o bk-apigateway-core-api

.PHONY: serve
serve: build
Expand Down
2 changes: 1 addition & 1 deletion src/core-api/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "apigateway-core",
Use: "core-api",
Short: "The core service for bk-apigateway",
Long: `The core service for bk-apigateway, it provide a lower-level API for apisix plugin and outer service`,
// Uncomment the following line if your bare application
Expand Down
48 changes: 48 additions & 0 deletions src/core-api/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* TencentBlueKing is pleased to support the open source community by making
* 蓝鲸智云 - API 网关(BlueKing - APIGateway) available.
* Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://opensource.org/licenses/MIT
*
* 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.
*
* We undertake not to change the open source license (MIT license) applicable
* to the current version of the project delivered to anyone in the future.
*/

package cmd

import (
"fmt"
"strings"

"github.com/spf13/cobra"

"core/pkg/version"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of core-api",
Long: `All software has versions. This is core-api's`,
Run: func(cmd *cobra.Command, args []string) {
info := []string{
"Version: " + version.Version,
"Commit: " + version.Commit,
"Build Time: " + version.BuildTime,
"Go Version: " + version.GoVersion,
}
fmt.Println(strings.Join(info, "\n"))
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
26 changes: 26 additions & 0 deletions src/core-api/pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* TencentBlueKing is pleased to support the open source community by making
* 蓝鲸智云 - API 网关(BlueKing - APIGateway) available.
* Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://opensource.org/licenses/MIT
*
* 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.
*
* We undertake not to change the open source license (MIT license) applicable
* to the current version of the project delivered to anyone in the future.
*/

package version

var (
Version = "0.0.0"
Commit = "none"
BuildTime = "unknown"
GoVersion = "1.20.X"
)

0 comments on commit 412259c

Please sign in to comment.