49 lines
1,009 B
Go
49 lines
1,009 B
Go
package data
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// type SocketCli struct {
|
|
// Client *socketio.Client
|
|
// }
|
|
|
|
func NewSocketCli(user, response_room string) *map[string]interface{} {
|
|
|
|
ticketUrl := "http://localhost:3001"
|
|
|
|
ticketForm := map[string]string{
|
|
"user": user,
|
|
"response_room": response_room,
|
|
}
|
|
|
|
ticketByte, _ := json.Marshal(ticketForm)
|
|
|
|
req, err := http.NewRequest("POST", ticketUrl, bytes.NewBuffer(ticketByte))
|
|
if err != nil {
|
|
fmt.Println("create request fail: ", err)
|
|
}
|
|
|
|
req.Header.Add("Content-Type", "application/json")
|
|
client := &http.Client{}
|
|
result, err := client.Do(req)
|
|
if err != nil {
|
|
fmt.Println("request fail: ", err)
|
|
}
|
|
defer result.Body.Close()
|
|
|
|
bill := &map[string]interface{}{}
|
|
decodeErr := json.NewDecoder(result.Body).Decode(bill)
|
|
if decodeErr != nil {
|
|
fmt.Println("decode request error: ", decodeErr)
|
|
}
|
|
|
|
if result.StatusCode != http.StatusCreated {
|
|
fmt.Println("not expected status: ", result.Status)
|
|
}
|
|
|
|
return bill
|
|
}
|