Updated clamrest

This commit is contained in:
Oliver 2015-07-26 14:13:19 +01:00
parent c9683ded05
commit e061bcc1fb

View file

@ -9,8 +9,11 @@ import (
"io/ioutil"
"net/http"
"github.com/dutchcoders/go-clamd"
"os"
)
var opts map[string]string
func init() {
log.SetOutput(ioutil.Discard)
}
@ -20,7 +23,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
//POST takes the uploaded file(s) and saves it to disk.
case "POST":
c := clamd.NewClamd("tcp://localhost:3310")
c := clamd.NewClamd(opts["CLAMD_CONNECTION"])
//get the multipart reader for the request.
reader, err := r.MultipartReader()
@ -61,7 +64,31 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
func main() {
opts = make(map[string]string)
for _, e := range os.Environ() {
pair := strings.Split(e, "=")
opts[pair[0]] = pair[1]
}
if opts["CLAMD_CONNECTION"] == "" {
opts["CLAMD_CONNECTION"] = "tcp://localhost:3031"
}
fmt.Printf("Starting clamav rest bridge\n")
fmt.Printf("Connecting to clamd on %v\n", opts["CLAMD_CONNECTION"])
clamd_test := clamd.NewClamd(opts["CLAMD_CONNECTION"])
clamd_test.Ping()
version, err := clamd_test.Version()
if err != nil {
fmt.Printf("Error getting clamd version: %v\n", err)
os.Exit(1)
}
for version_string := range version {
fmt.Printf("Clamd version: %v\n", version_string)
}
fmt.Printf("Connected to clamd on %v\n", opts["CLAMD_CONNECTION"])
http.HandleFunc("/scan", uploadHandler)