first commit
This commit is contained in:
33
services/users.go
Normal file
33
services/users.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"astra-events/config"
|
||||
"astra-events/model"
|
||||
"astra-events/pkg/api"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetUser(ID uint, header http.Header) (*model.User, error) {
|
||||
id := strconv.Itoa(int(ID))
|
||||
|
||||
data, err, _ := api.GetRequest(
|
||||
config.Env.MSHosts.UsersHost+"/"+id,
|
||||
header)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.New("Error Request to Users Service")
|
||||
}
|
||||
|
||||
u := new(model.User)
|
||||
|
||||
err = json.Unmarshal(data, &u)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.New("Bad Response from Users Service")
|
||||
}
|
||||
|
||||
return u, nil
|
||||
}
|
||||
Reference in New Issue
Block a user