mirror of
https://github.com/emo2007/block-accounting.git
synced 2024-11-13 22:06:27 +00:00
34 lines
539 B
Go
34 lines
539 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
|
|
}
|
|
|
|
func ResponseOK() ([]byte, error) {
|
|
return json.Marshal(&ok{Ok: true})
|
|
}
|