mirror of
https://github.com/emo2007/block-accounting.git
synced 2024-11-12 21:36:28 +00:00
34 lines
551 B
Go
34 lines
551 B
Go
package presenters
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
func CreateRequest[T any](r *http.Request) (*T, error) {
|
|
defer r.Body.Close()
|
|
|
|
data, err := io.ReadAll(r.Body)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error read request body. %w", err)
|
|
}
|
|
|
|
var request T
|
|
|
|
if err := json.Unmarshal(data, &request); err != nil {
|
|
return nil, fmt.Errorf("error unmarshal join request. %w", err)
|
|
}
|
|
|
|
return &request, nil
|
|
}
|
|
|
|
type ok struct {
|
|
Ok bool `json:"ok"`
|
|
}
|
|
|
|
func ResponseOK() ([]byte, error) {
|
|
return json.Marshal(&ok{Ok: true})
|
|
}
|