main.go 817 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import "C"
  3. import (
  4. "bytes"
  5. "fmt"
  6. "gitlab.alibaba-inc.com/pai_biz_arch/pairec"
  7. "io/ioutil"
  8. "net/http/httptest"
  9. "os"
  10. )
  11. //export CommandRun
  12. func CommandRun(configFile *C.char) bool {
  13. file := C.GoString(configFile)
  14. os.Setenv("CONFIG_PATH", file)
  15. os.Setenv("RUN_MODE", "COMMAND")
  16. pairec.Run()
  17. return true
  18. }
  19. //export Recommend
  20. func Recommend(requestBody *C.char) *C.char {
  21. body := C.GoString(requestBody)
  22. readBuf := bytes.NewBufferString(body)
  23. req := httptest.NewRequest("POST", "/api/recall", readBuf)
  24. w := httptest.NewRecorder()
  25. pairec.PairecApp.Handlers.ServeHTTP(w, req)
  26. resp := w.Result()
  27. defer resp.Body.Close()
  28. responseBody, _ := ioutil.ReadAll(resp.Body)
  29. fmt.Println(resp.StatusCode)
  30. fmt.Println(string(responseBody))
  31. return C.CString(string(responseBody))
  32. }
  33. func main() {
  34. }