From dea5801966f8c6753b3c91359132b13776c13e38 Mon Sep 17 00:00:00 2001 From: hq0101 <1273715732@qq.com> Date: Thu, 8 Aug 2024 22:45:56 +0800 Subject: [PATCH] add example --- Makefile | 6 +++++- README.md | 1 - examples/simple/main.go | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 examples/simple/main.go diff --git a/Makefile b/Makefile index 166aca7..64cce66 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ run: ## Run a controller from your host. # 定义应用名称和默认版本号 APP1 = clamd-ctl APP2 = clamd-api -DEFAULT_VERSION = v0.1.0 +DEFAULT_VERSION = v0.3.0 # 获取Git描述的版本号,如果未定义则使用默认值 # VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo $(DEFAULT_VERSION)) @@ -60,3 +60,7 @@ docker-build: ## Build docker image with the manager. .PHONY: docker-push docker-push: ## Push docker image with the manager. $(CONTAINER_TOOL) push ${IMG} + +.PHONY: swag-init +swag-init: + swag init -g cmd/clamd-api/main.go diff --git a/README.md b/README.md index 2624fd9..e72561f 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,6 @@ make run ![swagger](assets/swagger.png) - # clamd-ctl 使用手册 clamd-ctl是一个Go语言编写的命令行工具,用于与ClamAV服务器进行通信,并执行各种操作。 diff --git a/examples/simple/main.go b/examples/simple/main.go new file mode 100644 index 0000000..fbaaea4 --- /dev/null +++ b/examples/simple/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "encoding/json" + "fmt" + "github.com/hq0101/go-clamav/pkg/clamav" + "time" +) + +func main() { + client := clamav.NewClamClient("tcp", "192.168.127.131:3310", 10*time.Second, 30*time.Second) + + response, err := client.Ping() + if err != nil { + fmt.Println("Error:", err) + return + } + + fmt.Println("Response from ClamAV:", response) + + version, err := client.Version() + if err != nil { + fmt.Println("Error:", err) + return + } + fmt.Println("ClamAV Version:", version) + + stats, err := client.Stats() + if err != nil { + fmt.Println("Error:", err) + return + } + jsonResults, err := json.MarshalIndent(stats, "", " ") + if err != nil { + fmt.Printf("Failed to marshal results to JSON: %v\n", err) + return + } + + fmt.Println("ClamAV Stats:", string(jsonResults)) +}