You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
726 B
43 lines
726 B
4 years ago
|
package es
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"encoding/json"
|
||
|
"io"
|
||
|
"net/http"
|
||
|
"recook/configs"
|
||
|
)
|
||
|
|
||
|
var client *http.Client
|
||
|
|
||
|
func init() {
|
||
|
client = http.DefaultClient
|
||
|
}
|
||
|
|
||
|
type IKReq struct {
|
||
|
Text string `json:"text"`
|
||
|
Tokenizer string `json:"tokenizer"`
|
||
|
}
|
||
|
|
||
|
type IKResp struct {
|
||
|
Tokens []struct {
|
||
|
Token string `json:"token"`
|
||
|
} `json:"tokens"`
|
||
|
}
|
||
|
|
||
|
func GetIK(req IKReq) (res IKResp) {
|
||
|
data, _ := json.Marshal(req)
|
||
|
r, _ := http.NewRequest("POST", configs.ConfigEsAddress, bytes.NewReader(data))
|
||
|
r.Header = http.Header{
|
||
|
"content-type": []string{"application/json"},
|
||
|
}
|
||
|
resp, err := client.Do(r)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
defer resp.Body.Close()
|
||
|
result, _ := io.ReadAll(resp.Body)
|
||
|
_ = json.Unmarshal(result, &res)
|
||
|
return
|
||
|
}
|