Virus scanning rest api
This commit is contained in:
parent
e061bcc1fb
commit
3e087ebb07
7 changed files with 100 additions and 14 deletions
27
clamrest.go
27
clamrest.go
|
@ -19,11 +19,11 @@ func init() {
|
|||
}
|
||||
|
||||
//This is where the action happens.
|
||||
func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func scanHandler(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(opts["CLAMD_CONNECTION"])
|
||||
c := clamd.NewClamd(opts["CLAMD_PORT"])
|
||||
//get the multipart reader for the request.
|
||||
reader, err := r.MultipartReader()
|
||||
|
||||
|
@ -71,16 +71,16 @@ func main() {
|
|||
opts[pair[0]] = pair[1]
|
||||
}
|
||||
|
||||
if opts["CLAMD_CONNECTION"] == "" {
|
||||
opts["CLAMD_CONNECTION"] = "tcp://localhost:3031"
|
||||
if opts["CLAMD_PORT"] == "" {
|
||||
opts["CLAMD_PORT"] = "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"])
|
||||
fmt.Printf("Connecting to clamd on %v\n", opts["CLAMD_PORT"])
|
||||
clamd_test := clamd.NewClamd(opts["CLAMD_PORT"])
|
||||
clamd_test.Ping()
|
||||
version, err := clamd_test.Version()
|
||||
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting clamd version: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
@ -88,13 +88,12 @@ func main() {
|
|||
for version_string := range version {
|
||||
fmt.Printf("Clamd version: %v\n", version_string)
|
||||
}
|
||||
fmt.Printf("Connected to clamd on %v\n", opts["CLAMD_CONNECTION"])
|
||||
fmt.Printf("Connected to clamd on %v\n", opts["CLAMD_PORT"])
|
||||
|
||||
http.HandleFunc("/scan", uploadHandler)
|
||||
http.HandleFunc("/scan", scanHandler)
|
||||
|
||||
//static file handler.
|
||||
http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets"))))
|
||||
|
||||
//Listen on port 8080
|
||||
http.ListenAndServe(":3030", nil)
|
||||
//Listen on port PORT
|
||||
if opts["PORT"] == "" { opts["PORT"] = "9000" }
|
||||
fmt.Printf("Listening on port " + opts["PORT"])
|
||||
http.ListenAndServe(":" + opts["PORT"], nil)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue