Add simple route for /me

This commit is contained in:
Thomas Müller
2019-12-05 15:19:33 +01:00
parent b30fcde437
commit 6b4dd6ab2a
3 changed files with 32 additions and 0 deletions
+29
View File
@@ -1,6 +1,8 @@
package http
import (
"encoding/json"
"net/http"
"time"
"github.com/micro/go-micro/util/log"
@@ -8,8 +10,34 @@ import (
"github.com/owncloud/ocis-graph/pkg/config"
"github.com/owncloud/ocis-graph/pkg/flagset"
"github.com/owncloud/ocis-graph/pkg/version"
msgraph "github.com/yaegashi/msgraph.go/v1.0"
)
func handleMe(writer http.ResponseWriter, req *http.Request) {
displayName := "Alice"
id := "1234-5678-9000-000"
me := &msgraph.User{
DisplayName: &displayName,
GivenName: &displayName,
DirectoryObject: msgraph.DirectoryObject{
Entity: msgraph.Entity{
ID: &id,
},
},
}
js, err := json.Marshal(me)
if err != nil {
//p.srv.Logger().Errorf("owncloud-plugin: error encoding response as json %s", err)
writer.WriteHeader(http.StatusInternalServerError)
return
}
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(http.StatusOK)
writer.Write(js)
}
func Server(opts ...Option) (web.Service, error) {
options := newOptions(opts...)
log.Infof("Server [http] listening on [%s]", options.Config.HTTP.Addr)
@@ -35,5 +63,6 @@ func Server(opts ...Option) (web.Service, error) {
)
service.Init()
service.HandleFunc("/v1.0/me", handleMe)
return service, nil
}