alittle splitted mstorectl code; etc

This commit is contained in:
2026-03-05 12:26:14 +02:00
parent 80d6a244cf
commit 223ae2e96e
24 changed files with 631 additions and 104 deletions
@@ -7,7 +7,7 @@
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package command
package accountcmd
import (
"context"
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*
* This work is published and licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package accountcmd
import (
"net/url"
"path"
"strings"
)
func packUserinfo(resurseuri, username, password string) (string, error) {
var err error
var res string
if !strings.Contains(resurseuri, "://") {
resurseuri = "https://" + resurseuri
}
uri, err := url.Parse(resurseuri)
if err != nil {
return res, err
}
uri.Path = path.Clean(uri.Path)
if username != "" && password != "" {
uri.User = url.UserPassword(username, password)
}
res = uri.String()
return res, err
}
@@ -7,7 +7,7 @@
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package command
package accountcmd
import (
"context"
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*
* This work is published and licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package accountcmd
import (
"fmt"
"sigs.k8s.io/yaml"
)
func printResponse(res any, err error) {
type Response struct {
Error bool `json:"error" yaml:"error"`
Message string `json:"message,omitempty" yaml:"message,omitempty"`
Result any `json:"result,omitempty" yaml:"result,omitempty"`
}
resp := Response{}
if err != nil {
resp.Error = true
resp.Message = err.Error()
} else {
resp.Result = res
}
respBytes, _ := yaml.Marshal(resp)
fmt.Printf("---\n%s\n", string(respBytes))
}
@@ -7,7 +7,7 @@
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package command
package imagecmd
import (
"context"
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*
* This work is published and licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package imagecmd
import (
"fmt"
"sigs.k8s.io/yaml"
)
func printResponse(res any, err error) {
type Response struct {
Error bool `json:"error" yaml:"error"`
Message string `json:"message,omitempty" yaml:"message,omitempty"`
Result any `json:"result,omitempty" yaml:"result,omitempty"`
}
resp := Response{}
if err != nil {
resp.Error = true
resp.Message = err.Error()
} else {
resp.Result = res
}
respBytes, _ := yaml.Marshal(resp)
fmt.Printf("---\n%s\n", string(respBytes))
}
+1 -3
View File
@@ -11,13 +11,11 @@ package main
import (
"os"
"mstore/cmd/mstorectl/command"
)
func main() {
var err error
util := command.NewUtil()
util := NewUtil()
err = util.Build()
if err != nil {
os.Exit(1)
@@ -7,7 +7,7 @@
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package command
package main
import (
"fmt"
@@ -15,16 +15,17 @@ import (
"path/filepath"
"github.com/spf13/cobra"
"sigs.k8s.io/yaml"
"mstore/cmd/mstorectl/accountcmd"
"mstore/cmd/mstorectl/filecmd"
"mstore/cmd/mstorectl/imagecmd"
)
type Util struct {
accountcmd.AccountUtil
filecmd.FileUtil
ImageUtil
AccountUtil
GrantUtil
imagecmd.ImageUtil
accountcmd.GrantUtil
rootCmd *cobra.Command
}
@@ -67,20 +68,3 @@ func (util *Util) Exec(args []string) error {
func (util *Util) Hello(cmd *cobra.Command, args []string) {
fmt.Println("hello, world!")
}
func printResponse(res any, err error) {
type Response struct {
Error bool `json:"error" yaml:"error"`
Message string `json:"message,omitempty" yaml:"message,omitempty"`
Result any `json:"result,omitempty" yaml:"result,omitempty"`
}
resp := Response{}
if err != nil {
resp.Error = true
resp.Message = err.Error()
} else {
resp.Result = res
}
respBytes, _ := yaml.Marshal(resp)
fmt.Printf("---\n%s\n", string(respBytes))
}