Exemplo n.º 1
0
// MountOperandsController "mounts" a Operands resource controller on the given service.
func MountOperandsController(service *goa.Service, ctrl OperandsController) {
	initService(service)
	var h goa.Handler
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewAddOperandsContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Add(rctx)
	}
	service.Mux.Handle("GET", "/add/:left/:right", ctrl.MuxHandler("Add", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Operands"}, goa.KV{"action", "Add"}, goa.KV{"route", "GET /add/:left/:right"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewMultiplyOperandsContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Multiply(rctx)
	}
	service.Mux.Handle("GET", "/multiply/:left/:right", ctrl.MuxHandler("Multiply", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Operands"}, goa.KV{"action", "Multiply"}, goa.KV{"route", "GET /multiply/:left/:right"})
}
Exemplo n.º 2
0
// MountAuthenticationController "mounts" a Authentication resource controller on the given service.
func MountAuthenticationController(service *goa.Service, ctrl AuthenticationController) {
	initService(service)
	var h goa.Handler
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewCallbackResponseFromFacebookAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.CallbackResponseFromFacebook(rctx)
	}
	service.Mux.Handle("GET", "/FacebookCallback", ctrl.MuxHandler("CallbackResponseFromFacebook", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "CallbackResponseFromFacebook"}, goa.KV{"route", "GET /FacebookCallback"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewCallbackResponseFromGithubAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.CallbackResponseFromGithub(rctx)
	}
	service.Mux.Handle("GET", "/GithubCallback", ctrl.MuxHandler("CallbackResponseFromGithub", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "CallbackResponseFromGithub"}, goa.KV{"route", "GET /GithubCallback"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewCallbackResponseFromGoogleAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.CallbackResponseFromGoogle(rctx)
	}
	service.Mux.Handle("GET", "/GoogleCallback", ctrl.MuxHandler("CallbackResponseFromGoogle", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "CallbackResponseFromGoogle"}, goa.KV{"route", "GET /GoogleCallback"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewLogIntoFacebookAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.LogIntoFacebook(rctx)
	}
	service.Mux.Handle("GET", "/FacebookLogin", ctrl.MuxHandler("LogIntoFacebook", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "LogIntoFacebook"}, goa.KV{"route", "GET /FacebookLogin"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewLogIntoGithubAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.LogIntoGithub(rctx)
	}
	service.Mux.Handle("GET", "/GithubLogin", ctrl.MuxHandler("LogIntoGithub", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "LogIntoGithub"}, goa.KV{"route", "GET /GithubLogin"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewLogIntoGoogleAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.LogIntoGoogle(rctx)
	}
	service.Mux.Handle("GET", "/GoogleLogin", ctrl.MuxHandler("LogIntoGoogle", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "LogIntoGoogle"}, goa.KV{"route", "GET /GoogleLogin"})
}
Exemplo n.º 3
0
// LogIntoFacebook runs the Log into Google action.
func (c *AuthenticationController) LogIntoFacebook(ctx *app.LogIntoFacebookAuthenticationContext) error {
	w := goa.Response(ctx).ResponseWriter
	r := goa.Request(ctx).Request
	fbRedirectURL := &url.URL{
		Scheme: "http",
		Path:   facebook.Endpoint.AuthURL,
	}
	queries := fbRedirectURL.Query()
	queries.Set("app_id", facebookOauthConfig.ClientID)
	queries.Set("redirect_uri", facebookOauthConfig.RedirectURL)
	queries.Set("state", oauthStateString)
	fbRedirectURL.RawQuery = queries.Encode()
	goa.Info(ctx, "redirect", goa.KV{Key: "EscapedPath", Value: fbRedirectURL.RequestURI()})
	http.Redirect(w, r, fbRedirectURL.RequestURI(), http.StatusTemporaryRedirect)
	return nil
}
Exemplo n.º 4
0
// CallbackResponseFromFacebook runs the Callback response from Facebook action.
func (c *AuthenticationController) CallbackResponseFromFacebook(ctx *app.CallbackResponseFromFacebookAuthenticationContext) error {
	w := goa.Response(ctx).ResponseWriter
	r := goa.Request(ctx).Request

	code := r.FormValue("code")
	state := r.FormValue("state")
	// fmt.Fprintf(w, "Hello! Code is: %s", code)

	if state != oauthStateString {
		fmt.Printf("invalid oauth state, expected '%s', got '%s'\n", oauthStateString, state)
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return nil
	}
	token, err := facebookOauthConfig.Exchange(oauth2.NoContext, code)
	if err != nil {
		fmt.Println("Code exchange failed with:", err)
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return nil
	}

	fbTokenURL := &url.URL{
		Scheme: "http",
		Path:   facebook.Endpoint.AuthURL,
	}
	queries := fbTokenURL.Query()
	queries.Set("client_id", facebookOauthConfig.ClientID)
	queries.Set("redirect_uri", facebookOauthConfig.RedirectURL)
	queries.Set("client_secret", secrets.Facebook.Secret)
	queries.Set("code", code)
	fbTokenURL.RawQuery = queries.Encode()

	response, err := http.Get(fbTokenURL.RequestURI())
	if err != nil {
		return err
	}
	defer response.Body.Close()
	goa.Info(ctx, "token received", goa.KV{Key: "AccessToken", Value: token.AccessToken})

	return nil
}
Exemplo n.º 5
0
// MountController mounts the JavaScript example controller under "/js".
func MountController(service *goa.Service) {
	// Serve static files under js
	service.ServeFiles("/js/*filepath", "/Users/nii236/Go/src/github.com/nii236/go-react-webpack/js")
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "JS"}, goa.KV{"action", "ServeFiles"}, goa.KV{"route", "GET /js/*"})
}
Exemplo n.º 6
0
func (l *TestLog) Info(ctx context.Context, msg string, data ...goa.KV) {
	l.infoEntries = append(l.infoEntries, &LogEntry{ctx, msg, data})
}

func (l *TestLog) Error(ctx context.Context, msg string, data ...goa.KV) {
	l.errorEntries = append(l.errorEntries, &LogEntry{ctx, msg, data})
}

var _ = Describe("Info and Error", func() {
	Context("with a nil Log", func() {
		BeforeEach(func() {
			goa.Log = nil
		})

		It("Info doesn't log and doesn't crash", func() {
			Ω(func() { goa.Info(nil, "foo") }).ShouldNot(Panic())
		})

		It("Error doesn't log and doesn't crash", func() {
			Ω(func() { goa.Error(nil, "foo") }).ShouldNot(Panic())
		})
	})

	Context("with a valid Log", func() {
		var testLog *TestLog
		var ctx context.Context
		ctxData := []goa.KV{{"ctxData", true}, {"other", 42}}
		data := []goa.KV{{"data", "foo"}}
		const msg = "message"

		BeforeEach(func() {