Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
hq0101 committed Aug 8, 2024
1 parent dfbce1e commit dea5801
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ make run

![swagger](assets/swagger.png)


# clamd-ctl 使用手册

clamd-ctl是一个Go语言编写的命令行工具,用于与ClamAV服务器进行通信,并执行各种操作。
Expand Down
40 changes: 40 additions & 0 deletions examples/simple/main.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit dea5801

Please sign in to comment.