fmt/gomod update
This commit is contained in:
43
cmd/cmd.go
43
cmd/cmd.go
@@ -18,23 +18,44 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/go-connections/sockets"
|
||||
"github.com/gostor/gotgt/pkg/api/client"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/gostor/gotgt/pkg/version"
|
||||
)
|
||||
|
||||
func NewCommand(cli *client.Client) *cobra.Command {
|
||||
func NewCommand() *cobra.Command {
|
||||
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: ``,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: 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 {
|
||||
fmt.Fprintf(os.Stderr, "%v", err)
|
||||
return err
|
||||
}
|
||||
// Do Stuff Here
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.PersistentFlags().StringVar(&host, "host", host, "Endpoint for SCSI target daemon")
|
||||
cmd.AddCommand(
|
||||
newDaemonCommand(cli),
|
||||
newDaemonCommand(),
|
||||
newCreateCommand(cli),
|
||||
newRemoveCommand(cli),
|
||||
newListCommand(cli),
|
||||
@@ -43,6 +64,22 @@ func NewCommand(cli *client.Client) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func newHTTPClient(host string) (*http.Client, error) {
|
||||
tr := &http.Transport{
|
||||
TLSClientConfig: nil,
|
||||
}
|
||||
proto, addr, _, err := client.ParseHost(host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sockets.ConfigureTransport(tr, proto, addr)
|
||||
|
||||
return &http.Client{
|
||||
Transport: tr,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NoArgs validate args and returns an error if there are any args
|
||||
func NoArgs(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/gostor/gotgt/pkg/api/client"
|
||||
"github.com/gostor/gotgt/pkg/apiserver"
|
||||
"github.com/gostor/gotgt/pkg/config"
|
||||
_ "github.com/gostor/gotgt/pkg/port/iscsit"
|
||||
@@ -33,7 +32,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func newDaemonCommand(cli *client.Client) *cobra.Command {
|
||||
func newDaemonCommand() *cobra.Command {
|
||||
var host string
|
||||
var driver string
|
||||
var logLevel string
|
||||
@@ -48,7 +47,6 @@ func newDaemonCommand(cli *client.Client) *cobra.Command {
|
||||
}
|
||||
flags := cmd.Flags()
|
||||
flags.StringVar(&logLevel, "log", "info", "Log level of SCSI target daemon")
|
||||
flags.StringVar(&host, "host", "tcp://127.0.0.1:23457", "Host for SCSI target daemon")
|
||||
flags.StringVar(&driver, "driver", "iscsi", "SCSI low level driver")
|
||||
flags.BoolVar(&blockMultipleHosts, "block-multiple-hosts", false, "Disable login from multiple hosts")
|
||||
return cmd
|
||||
|
||||
Reference in New Issue
Block a user