implement macros & includes

This commit is contained in:
Stanislav Seletskiy
2019-08-02 22:58:08 +03:00
parent e77e589494
commit 07a8e3f9d7
15 changed files with 870 additions and 149 deletions

View File

@@ -12,8 +12,6 @@ import (
"strings"
"github.com/bndr/gopencils"
"github.com/kovetskiy/lorg"
"github.com/reconquest/cog"
"github.com/reconquest/karma-go"
)
@@ -59,20 +57,6 @@ type AttachmentInfo struct {
} `json:"_links"`
}
func discarder() *lorg.Log {
stderr := lorg.NewLog()
stderr.SetOutput(ioutil.Discard)
return stderr
}
var (
log = cog.NewLogger(discarder())
)
func SetLogger(logger *cog.Logger) {
log = logger
}
type form struct {
buffer io.Reader
writer *multipart.Writer
@@ -471,6 +455,35 @@ func (api *API) UpdatePage(
return nil
}
func (api *API) GetUserByName(name string) (*User, error) {
var response struct {
Results []struct {
User User
}
}
_, err := api.rest.
Res("search").
Res("user", &response).
Get(map[string]string{
"cql": fmt.Sprintf("user.fullname~%q", name),
})
if err != nil {
return nil, err
}
if len(response.Results) == 0 {
return nil, karma.
Describe("name", name).
Reason(
"user with given name is not found",
)
}
return &response.Results[0].User, nil
}
func (api *API) GetCurrentUser() (*User, error) {
var user User