From a6cf150e950179d199d56c032d72f7cd1a5d9854 Mon Sep 17 00:00:00 2001 From: Wenhua Shi Date: Mon, 17 Apr 2023 19:29:01 +0800 Subject: [PATCH] fix some issues --- cmd/cmd.go | 17 +++++++++-------- examples/config.json | 34 ++++++++++++++++++---------------- pkg/api/client/target_list.go | 2 +- pkg/apiserver/apiserver.go | 2 +- pkg/version/version.go | 2 +- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 550293f..0483668 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -30,23 +30,24 @@ import ( ) func NewCommand() *cobra.Command { - var cli *client.Client + var cli client.Client var host string = "tcp://127.0.0.1:23457" var cmd = &cobra.Command{ Use: "gotgt", Short: "Gotgt is a very fast and stable SCSI target framework", Long: ``, - RunE: func(cmd *cobra.Command, args []string) error { + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { httpClient, err := newHTTPClient(host) if err != nil { fmt.Fprintf(os.Stderr, "%v", err) return err } - cli, err = client.NewClient(host, version.Version, httpClient, nil) - if err != nil { + if _cli, err := client.NewClient(host, version.Version, httpClient, nil); err != nil { fmt.Fprintf(os.Stderr, "%v", err) return err + } else { + cli = *_cli } // Do Stuff Here return nil @@ -56,10 +57,10 @@ func NewCommand() *cobra.Command { cmd.PersistentFlags().StringVar(&host, "host", host, "Endpoint for SCSI target daemon") cmd.AddCommand( newDaemonCommand(), - newCreateCommand(cli), - newRemoveCommand(cli), - newListCommand(cli), - newVersionCommand(cli), + newCreateCommand(&cli), + newRemoveCommand(&cli), + newListCommand(&cli), + newVersionCommand(&cli), ) return cmd } diff --git a/examples/config.json b/examples/config.json index 0e749e7..e24362f 100644 --- a/examples/config.json +++ b/examples/config.json @@ -1,27 +1,29 @@ { - "storages":[ + "storages": [ { - "deviceID":1000, - "path":"file:/var/tmp/disk.img", - "online":true, - "thinProvisioning":false, - "blockShift": 9, + "deviceID": 1000, + "path": "file:/var/tmp/disk.img", + "online": true, + "thinProvisioning": false, + "blockShift": 9 } ], - "iscsiportals":[ + "iscsiportals": [ { - "id":0, - "portal":"127.0.0.1:3260" + "id": 0, + "portal": "127.0.0.1:3260" } ], - "iscsitargets":{ - "iqn.2016-09.com.gotgt.gostor:02:example-tgt-0":{ - "tpgts":{ - "1":[0] + "iscsitargets": { + "iqn.2016-09.com.gotgt.gostor:02:example-tgt-0": { + "tpgts": { + "1": [ + 0 + ] }, - "luns":{ - "0":1000 + "luns": { + "0": 1000 } } } -} +} \ No newline at end of file diff --git a/pkg/api/client/target_list.go b/pkg/api/client/target_list.go index 2156624..fc90d07 100644 --- a/pkg/api/client/target_list.go +++ b/pkg/api/client/target_list.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index 0f059a7..6803fd6 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -39,7 +39,7 @@ import ( // versionMatcher defines a variable matcher to be parsed by the router // when a request is about to be served. -const versionMatcher = "/v{version:[0-9.]+}" +const versionMatcher = "/v{version:[0-9.]+(?:-dirty)}" // Config provides the configuration for the API server type Config struct { diff --git a/pkg/version/version.go b/pkg/version/version.go index 21ff1d0..247ad17 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -23,7 +23,7 @@ import ( "runtime" ) -const ( +var ( // Version shows the version of gotgt. Version = "Not provided." // SCSIVersion string MUST be shorter than 4 characters