From d1c5fb116222f2f299ad85d442e965388b01ffcf Mon Sep 17 00:00:00 2001 From: sianao Date: Tue, 25 Mar 2025 18:28:06 +0800 Subject: [PATCH] add it --- .gitignore | 2 +- lib/http/images/list.go | 1 + lib/http/network/list.go | 20 +++++ lib/http/system/basic.go | 20 +++++ lib/http/system/info.go | 20 +++++ lib/http/volume/list.go | 20 +++++ lib/model/basic.go | 175 +++++++++++++++++++++++++++++++++++++++ lib/model/network.go | 35 ++++++++ lib/model/volume.go | 18 ++++ service/auth/sigin.go | 24 ++++++ 10 files changed, 334 insertions(+), 1 deletion(-) create mode 100644 lib/http/images/list.go create mode 100644 lib/http/network/list.go create mode 100644 lib/http/system/basic.go create mode 100644 lib/http/system/info.go create mode 100644 lib/http/volume/list.go create mode 100644 lib/model/basic.go create mode 100644 lib/model/network.go create mode 100644 lib/model/volume.go create mode 100644 service/auth/sigin.go diff --git a/.gitignore b/.gitignore index 6f72f89..0352e67 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out - +floares # Dependency directories (remove the comment below to include it) # vendor/ diff --git a/lib/http/images/list.go b/lib/http/images/list.go new file mode 100644 index 0000000..a8d61a3 --- /dev/null +++ b/lib/http/images/list.go @@ -0,0 +1 @@ +package images diff --git a/lib/http/network/list.go b/lib/http/network/list.go new file mode 100644 index 0000000..27a4ccd --- /dev/null +++ b/lib/http/network/list.go @@ -0,0 +1,20 @@ +package network + +import ( + "encoding/json" + "floares/lib/model" + "log" + "net/http" +) + +func ListJsons() []model.NetWorkJson { + req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/networks", nil) + res, err := http.DefaultClient.Do(req) + if err != nil { + log.Println("request for network list error:", err) + return []model.NetWorkJson{} + } + var result []model.NetWorkJson + err = json.NewDecoder(res.Body).Decode(&result) + return result +} diff --git a/lib/http/system/basic.go b/lib/http/system/basic.go new file mode 100644 index 0000000..08e8b44 --- /dev/null +++ b/lib/http/system/basic.go @@ -0,0 +1,20 @@ +package system + +import ( + "encoding/json" + "floares/lib/model" + "log" + "net/http" +) + +func Version() model.Version { + req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/version", nil) + res, err := http.DefaultClient.Do(req) + if err != nil { + log.Println("request for version list error:", err) + return model.Version{} + } + var result model.Version + err = json.NewDecoder(res.Body).Decode(&result) + return result +} diff --git a/lib/http/system/info.go b/lib/http/system/info.go new file mode 100644 index 0000000..bdbd809 --- /dev/null +++ b/lib/http/system/info.go @@ -0,0 +1,20 @@ +package system + +import ( + "encoding/json" + "floares/lib/model" + "log" + "net/http" +) + +func Info() model.Info { + req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/info", nil) + res, err := http.DefaultClient.Do(req) + if err != nil { + log.Println("request for info list error:", err) + return model.Info{} + } + var result model.Info + err = json.NewDecoder(res.Body).Decode(&result) + return result +} diff --git a/lib/http/volume/list.go b/lib/http/volume/list.go new file mode 100644 index 0000000..29c3516 --- /dev/null +++ b/lib/http/volume/list.go @@ -0,0 +1,20 @@ +package volume + +import ( + "encoding/json" + "floares/lib/model" + "log" + "net/http" +) + +func ListJsons() model.VolumesJson { + req, _ := http.NewRequest("GET", "http://127.0.0.1:8888/volumes", nil) + res, err := http.DefaultClient.Do(req) + if err != nil { + log.Println("request for volume list error:", err) + return model.VolumesJson{} + } + var result model.VolumesJson + err = json.NewDecoder(res.Body).Decode(&result) + return result +} diff --git a/lib/model/basic.go b/lib/model/basic.go new file mode 100644 index 0000000..adc5f54 --- /dev/null +++ b/lib/model/basic.go @@ -0,0 +1,175 @@ +package model + +import "time" + +type Version struct { + Platform struct { + Name string `json:"Name"` + } `json:"Platform"` + Components []struct { + Name string `json:"Name"` + Version string `json:"Version"` + Details struct { + APIVersion string `json:"APIVersion,omitempty"` + Arch string `json:"Arch,omitempty"` + BuildTime time.Time `json:"BuildTime,omitempty"` + Experimental string `json:"Experimental,omitempty"` + GitCommit string `json:"GitCommit,omitempty"` + GoVersion string `json:"GoVersion,omitempty"` + KernelVersion string `json:"KernelVersion,omitempty"` + MinAPIVersion string `json:"MinAPIVersion,omitempty"` + Os string `json:"Os,omitempty"` + Package string `json:"Package,omitempty"` + } `json:"Details"` + } `json:"Components"` + Version string `json:"Version"` + ApiVersion string `json:"ApiVersion"` + MinAPIVersion string `json:"MinAPIVersion"` + GitCommit string `json:"GitCommit"` + GoVersion string `json:"GoVersion"` + Os string `json:"Os"` + Arch string `json:"Arch"` + KernelVersion string `json:"KernelVersion"` + BuildTime time.Time `json:"BuildTime"` +} +type Info struct { + ID string `json:"ID"` + Containers int `json:"Containers"` + ContainersRunning int `json:"ContainersRunning"` + ContainersPaused int `json:"ContainersPaused"` + ContainersStopped int `json:"ContainersStopped"` + Images int `json:"Images"` + Driver string `json:"Driver"` + DriverStatus [][]string `json:"DriverStatus"` + Plugins struct { + Volume []string `json:"Volume"` + Network []string `json:"Network"` + Authorization interface{} `json:"Authorization"` + Log []string `json:"Log"` + } `json:"Plugins"` + MemoryLimit bool `json:"MemoryLimit"` + SwapLimit bool `json:"SwapLimit"` + CpuCfsPeriod bool `json:"CpuCfsPeriod"` + CpuCfsQuota bool `json:"CpuCfsQuota"` + CPUShares bool `json:"CPUShares"` + CPUSet bool `json:"CPUSet"` + PidsLimit bool `json:"PidsLimit"` + IPv4Forwarding bool `json:"IPv4Forwarding"` + BridgeNfIptables bool `json:"BridgeNfIptables"` + BridgeNfIp6Tables bool `json:"BridgeNfIp6tables"` + Debug bool `json:"Debug"` + NFd int `json:"NFd"` + OomKillDisable bool `json:"OomKillDisable"` + NGoroutines int `json:"NGoroutines"` + SystemTime time.Time `json:"SystemTime"` + LoggingDriver string `json:"LoggingDriver"` + CgroupDriver string `json:"CgroupDriver"` + NEventsListener int `json:"NEventsListener"` + KernelVersion string `json:"KernelVersion"` + OperatingSystem string `json:"OperatingSystem"` + OSVersion string `json:"OSVersion"` + OSType string `json:"OSType"` + Architecture string `json:"Architecture"` + IndexServerAddress string `json:"IndexServerAddress"` + RegistryConfig struct { + AllowNondistributableArtifactsCIDRs []interface{} `json:"AllowNondistributableArtifactsCIDRs"` + AllowNondistributableArtifactsHostnames []interface{} `json:"AllowNondistributableArtifactsHostnames"` + InsecureRegistryCIDRs []interface{} `json:"InsecureRegistryCIDRs"` + IndexConfigs struct { + } `json:"IndexConfigs"` + Mirrors []interface{} `json:"Mirrors"` + } `json:"RegistryConfig"` + NCPU int `json:"NCPU"` + MemTotal int64 `json:"MemTotal"` + GenericResources interface{} `json:"GenericResources"` + DockerRootDir string `json:"DockerRootDir"` + HttpProxy string `json:"HttpProxy"` + HttpsProxy string `json:"HttpsProxy"` + NoProxy string `json:"NoProxy"` + Name string `json:"Name"` + Labels interface{} `json:"Labels"` + ExperimentalBuild bool `json:"ExperimentalBuild"` + ServerVersion string `json:"ServerVersion"` + Runtimes struct { + Crun struct { + Path string `json:"path"` + } `json:"crun"` + CrunVm struct { + Path string `json:"path"` + } `json:"crun-vm"` + CrunWasm struct { + Path string `json:"path"` + } `json:"crun-wasm"` + Kata struct { + Path string `json:"path"` + } `json:"kata"` + Krun struct { + Path string `json:"path"` + } `json:"krun"` + Ocijail struct { + Path string `json:"path"` + } `json:"ocijail"` + Runc struct { + Path string `json:"path"` + } `json:"runc"` + Runj struct { + Path string `json:"path"` + } `json:"runj"` + Runsc struct { + Path string `json:"path"` + } `json:"runsc"` + Youki struct { + Path string `json:"path"` + } `json:"youki"` + } `json:"Runtimes"` + DefaultRuntime string `json:"DefaultRuntime"` + Swarm struct { + NodeID string `json:"NodeID"` + NodeAddr string `json:"NodeAddr"` + LocalNodeState string `json:"LocalNodeState"` + ControlAvailable bool `json:"ControlAvailable"` + Error string `json:"Error"` + RemoteManagers interface{} `json:"RemoteManagers"` + } `json:"Swarm"` + LiveRestoreEnabled bool `json:"LiveRestoreEnabled"` + Isolation string `json:"Isolation"` + InitBinary string `json:"InitBinary"` + ContainerdCommit struct { + ID string `json:"ID"` + Expected string `json:"Expected"` + } `json:"ContainerdCommit"` + RuncCommit struct { + ID string `json:"ID"` + Expected string `json:"Expected"` + } `json:"RuncCommit"` + InitCommit struct { + ID string `json:"ID"` + Expected string `json:"Expected"` + } `json:"InitCommit"` + SecurityOptions []string `json:"SecurityOptions"` + ProductLicense string `json:"ProductLicense"` + CDISpecDirs interface{} `json:"CDISpecDirs"` + Warnings []interface{} `json:"Warnings"` + BuildahVersion string `json:"BuildahVersion"` + CPURealtimePeriod bool `json:"CPURealtimePeriod"` + CPURealtimeRuntime bool `json:"CPURealtimeRuntime"` + CgroupVersion string `json:"CgroupVersion"` + Rootless bool `json:"Rootless"` + SwapFree int64 `json:"SwapFree"` + SwapTotal int64 `json:"SwapTotal"` + Uptime string `json:"Uptime"` +} +type BasicInfo struct { + Platform struct { + Name string `json:"Name"` + } `json:"Platform"` + Uptime string `json:"Uptime"` + DefaultRuntime string `json:"DefaultRuntime"` + NCPU int `json:"NCPU"` + MemTotal int64 `json:"MemTotal"` + OperatingSystem string `json:"OperatingSystem"` + Images int `json:"Images"` + Containers int `json:"Containers"` + Networks int `json:"Networks"` + Volumes int `json:"Volumes"` +} diff --git a/lib/model/network.go b/lib/model/network.go new file mode 100644 index 0000000..b4d0801 --- /dev/null +++ b/lib/model/network.go @@ -0,0 +1,35 @@ +package model + +import "time" + +type NetWorkJson struct { + Name string `json:"Name"` + Id string `json:"Id"` + Created time.Time `json:"Created"` + Scope string `json:"Scope"` + Driver string `json:"Driver"` + EnableIPv6 bool `json:"EnableIPv6"` + IPAM struct { + Driver string `json:"Driver"` + Options struct { + Driver string `json:"driver"` + } `json:"Options"` + Config []struct { + Subnet string `json:"Subnet"` + Gateway string `json:"Gateway"` + } `json:"Config"` + } `json:"IPAM"` + Internal bool `json:"Internal"` + Attachable bool `json:"Attachable"` + Ingress bool `json:"Ingress"` + ConfigFrom struct { + Network string `json:"Network"` + } `json:"ConfigFrom"` + ConfigOnly bool `json:"ConfigOnly"` + Containers struct { + } `json:"Containers"` + Options struct { + } `json:"Options"` + Labels struct { + } `json:"Labels"` +} diff --git a/lib/model/volume.go b/lib/model/volume.go new file mode 100644 index 0000000..71ba5ca --- /dev/null +++ b/lib/model/volume.go @@ -0,0 +1,18 @@ +package model + +import "time" + +type VolumesJson struct { + Volumes []struct { + CreatedAt time.Time `json:"CreatedAt"` + Driver string `json:"Driver"` + Labels struct { + } `json:"Labels"` + Mountpoint string `json:"Mountpoint"` + Name string `json:"Name"` + Options struct { + } `json:"Options"` + Scope string `json:"Scope"` + } `json:"Volumes"` + Warnings []interface{} `json:"Warnings"` +} diff --git a/service/auth/sigin.go b/service/auth/sigin.go new file mode 100644 index 0000000..fb45fb6 --- /dev/null +++ b/service/auth/sigin.go @@ -0,0 +1,24 @@ +package auth + +import ( + "github.com/gin-gonic/gin" + "log" + "net/http" +) + +type SignReq struct { + Email string `json:"email"` + Password string `json:"password"` +} + +func Sign(c *gin.Context) { + var req SignReq + if err := c.ShouldBindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + } + jwt. + c.JSON(http.StatusOK, gin.H{ + "data": "hello world", + }) + log.Println(req) +}