-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from stefannica/version
Add version information to server and CLI
- Loading branch information
Showing
12 changed files
with
294 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package design | ||
|
||
import ( | ||
. "goa.design/goa/v3/dsl" | ||
) | ||
|
||
var _ = Service("version", func() { | ||
Description("The version service displays version information.") | ||
|
||
Method("get", func() { | ||
Description("Retrieve version information.") | ||
|
||
Result(VersionInfo) | ||
|
||
HTTP(func() { | ||
GET("/version") | ||
Response(StatusOK) | ||
}) | ||
|
||
GRPC(func() { | ||
Response(CodeOK) | ||
}) | ||
}) | ||
}) | ||
|
||
// VersionInfo describes server version information | ||
var VersionInfo = Type("VersionInfo", func() { | ||
|
||
Field(1, "version", String, "The server version", func() { | ||
Example("v1.0") | ||
}) | ||
Field(2, "gitCommit", String, "The git commit corresponding to the running server version", func() { | ||
Example("4833d673") | ||
}) | ||
Field(3, "buildDate", String, "The date the server binary was built", func() { | ||
Example("2021-06-02T10:21:03Z") | ||
}) | ||
Field(4, "golangVersion", String, "The GO version used to build the binary", func() { | ||
Example("go1.16.0") | ||
}) | ||
Field(5, "golangCompiler", String, "The GO compiler used to build the binary", func() { | ||
Example("gc") | ||
}) | ||
Field(6, "platform", String, "The platform where the server is running", func() { | ||
Example("linux/amd64") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
goahttp "goa.design/goa/v3/http" | ||
|
||
versionc "github.com/fuseml/fuseml-core/gen/http/version/client" | ||
"github.com/fuseml/fuseml-core/gen/version" | ||
) | ||
|
||
// VersionClient holds a client for Version | ||
type VersionClient struct { | ||
c *versionc.Client | ||
} | ||
|
||
// NewVersionClient initializes a VersionClient | ||
func NewVersionClient(scheme string, host string, doer goahttp.Doer, encoder func(*http.Request) goahttp.Encoder, | ||
decoder func(*http.Response) goahttp.Decoder, verbose bool) *VersionClient { | ||
vc := &VersionClient{versionc.NewClient(scheme, host, doer, encoder, decoder, verbose)} | ||
return vc | ||
} | ||
|
||
// Get version information. | ||
func (vc *VersionClient) Get() (*version.VersionInfo, error) { | ||
response, err := vc.c.Get()(context.Background(), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return response.(*version.VersionInfo), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
versionc "github.com/fuseml/fuseml-core/gen/version" | ||
"github.com/fuseml/fuseml-core/pkg/cli/client" | ||
"github.com/fuseml/fuseml-core/pkg/cli/common" | ||
"github.com/fuseml/fuseml-core/pkg/version" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// versionOptions holds the options for the 'version' sub command | ||
type versionOptions struct { | ||
client.Clients | ||
global *common.GlobalOptions | ||
format *common.FormattingOptions | ||
} | ||
|
||
// newVersionOptions initializes a versionOptions struct | ||
func newVersionOptions(gOpt *common.GlobalOptions) *versionOptions { | ||
res := &versionOptions{global: gOpt} | ||
res.format = common.NewSingleValueFormattingOptions() | ||
return res | ||
} | ||
|
||
// NewCmdVersion creates and returns the cobra command for the `version` CLI command | ||
func NewCmdVersion(gOpt *common.GlobalOptions) *cobra.Command { | ||
|
||
o := newVersionOptions(gOpt) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "display version information", | ||
Long: `Display version information about the CLI and server`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
common.CheckErr(o.run()) | ||
}, | ||
Args: cobra.ExactArgs(0), | ||
} | ||
|
||
o.format.AddSingleValueFormattingFlags(cmd, common.FormatYAML) | ||
return cmd | ||
} | ||
|
||
func (o *versionOptions) run() error { | ||
var data = struct { | ||
Client *version.Info | ||
Server *versionc.VersionInfo | ||
}{} | ||
|
||
data.Client = version.GetInfo() | ||
err := o.InitializeClients(o.global.URL, o.global.Timeout, o.global.Verbose) | ||
|
||
if err == nil { | ||
data.Server, err = o.VersionClient.Get() | ||
} | ||
|
||
o.format.FormatValue(os.Stdout, data) | ||
|
||
if err != nil { | ||
return fmt.Errorf("could not retrieve server version information: %s", err.Error()) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.