generated from go-kratos/kratos-layout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
107 lines (97 loc) · 2.64 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright (c) 2024 OrigAdmin. All rights reserved.
*/
// Package main is the main package
package main
import (
"context"
"fmt"
"os"
goversion "github.com/caarlos0/go-version"
_ "github.com/origadmin/contrib/consul/config"
_ "github.com/origadmin/contrib/consul/registry"
"github.com/spf13/cobra"
"origadmin/basic-layout/cmd"
"origadmin/basic-layout/internal/bootstrap"
)
// build tool goreleaser tags
//
//nolint:gochecknoglobals
var (
version = ""
commit = ""
treeState = ""
date = ""
builtBy = ""
debug = false
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "origadmin",
Short: "OrigAdmin Backend is a distributed backend management system with a focus on scalability, security, and flexibility.",
Run: func(cmd *cobra.Command, args []string) {
// Place your logic here
// _ = cmd.Help()
},
}
func init() {
goinfo := buildVersion(version, commit, date, builtBy, treeState)
rootCmd.SilenceUsage = true
rootCmd.SilenceErrors = true
rootCmd.CompletionOptions.HiddenDefaultCmd = true
rootCmd.CompletionOptions.DisableNoDescFlag = true
rootCmd.AddCommand(cmd.Commands()...)
rootCmd.Version = goinfo.String()
}
// @title OrigAdmin Backend API
// @version v1.0.0
// @description A distributed backend management system with a focus on scalability, security, and flexibility.
// @contact.name OrigAdmin
// @contact.url https://github.com/origadmin
// @license.name MIT
// @license.url https://github.com/origadmin/origadmin/blob/main/LICENSE.md
//
// @host localhost:28080
// @basepath /api/v1
// @schemes http https
//
// @securitydefinitions.basic Basic
//
// @securitydefinitions.apikey Bearer
// @in header
// @name Authorization
func main() {
Execute()
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.ExecuteContext(context.Background())
if err != nil {
fmt.Printf("Command executed with error:\n%v\n", err)
os.Exit(1)
}
}
func buildVersion(version, commit, date, builtBy, treeState string) goversion.Info {
return goversion.GetVersionInfo(
goversion.WithAppDetails(bootstrap.Application, bootstrap.Description, bootstrap.WebSite),
func(i *goversion.Info) {
i.ASCIIName = bootstrap.UI
if commit != "" {
i.GitCommit = commit
}
if version != "" {
i.GitVersion = version
}
if treeState != "" {
i.GitTreeState = treeState
}
if date != "" {
i.BuildDate = date
}
if builtBy != "" {
i.BuiltBy = builtBy
}
},
)
}