package knc

import (
	"fmt"
	"os/exec"
	"encoding/json"
	"keycommon/reqtarget"
)

type KncServer struct {
	Hostname string
}

func (k KncServer) kncRequest(data []byte) ([]byte, error) {
	cmd := exec.Command("/usr/bin/knc", fmt.Sprintf("host@%s", k.Hostname), "20575")

	stdin, err := cmd.StdinPipe()
	if err != nil {
		return nil, err
	}

	go func() {
		defer stdin.Close()
		stdin.Write(data)
	}()

	response, err := cmd.Output()
	if err != nil {
		return nil, err
	}

	return response, nil
}

func (k KncServer) SendRequests(reqs []reqtarget.Request) ([]string, error) {
	raw_reqs, err := json.Marshal(reqs)
	if err != nil {
		return nil, err
	}

	raw_resps, err := k.kncRequest(raw_reqs)
	if err != nil {
		return nil, err
	}

	resps := []string{}
	err = json.Unmarshal(raw_resps, &resps)
	if err != nil {
		return nil, err
	}

	return resps, nil
}

package knc

import (
	"fmt"
	"os/exec"
)

func Request(host string, data []byte) ([]byte, error) {
	cmd := exec.Command("/usr/bin/knc", fmt.Sprintf("host@%s", host), "20575")

	stdin, err := cmd.StdinPipe()
	if err != nil {
		return nil, err
	}

	go func() {
		defer stdin.Close()
		stdin.Write(data)
	}()

	response, err := cmd.Output()
	if err != nil {
		return nil, err
	}

	return response, nil
}

--- 
+++ 
@@ -3,10 +3,16 @@
 import (
 	"fmt"
 	"os/exec"
+	"encoding/json"
+	"keycommon/reqtarget"
 )
 
-func Request(host string, data []byte) ([]byte, error) {
-	cmd := exec.Command("/usr/bin/knc", fmt.Sprintf("host@%s", host), "20575")
+type KncServer struct {
+	Hostname string
+}
+
+func (k KncServer) kncRequest(data []byte) ([]byte, error) {
+	cmd := exec.Command("/usr/bin/knc", fmt.Sprintf("host@%s", k.Hostname), "20575")
 
 	stdin, err := cmd.StdinPipe()
 	if err != nil {
@@ -25,3 +31,23 @@
 
 	return response, nil
 }
+
+func (k KncServer) SendRequests(reqs []reqtarget.Request) ([]string, error) {
+	raw_reqs, err := json.Marshal(reqs)
+	if err != nil {
+		return nil, err
+	}
+
+	raw_resps, err := k.kncRequest(raw_reqs)
+	if err != nil {
+		return nil, err
+	}
+
+	resps := []string{}
+	err = json.Unmarshal(raw_resps, &resps)
+	if err != nil {
+		return nil, err
+	}
+
+	return resps, nil
+}
Make KncServer a reqtarget implementation
