// ShowHandler handles requests to get a particular resource by ID.
331537
func (rc *ResourceController) ShowHandler(c *gin.Context) {
	c.Set("Action", "read")
	_, err := rc.LoadResource(c)
	if err != nil && err != ErrNotFound {
		c.AbortWithError(http.StatusInternalServerError, err)
		return
	}

	if err == ErrNotFound {
		c.Status(http.StatusNotFound)
		return
	}
	resource, _ := c.Get(rc.Name)
	c.JSON(http.StatusOK, resource)
}
573941
func (app *App) UseHandler(h Handler) *App {
	app.mds = append(app.mds, h.Serve)
	return app
}
502653
func WrapHandler(h http.Handler) HandlerFunc {
	return func(c Context) error {
		h.ServeHTTP(c.Response(), c.Request())
		return nil
	}
}
753577
func (m *MetaClient) ShowCluster(ctx context.Context) (*Cluster, error) {
	res, err := m.Do(ctx, "/show-cluster", "GET", m.authorizer, nil, nil)
	if err != nil {
		return nil, err
	}

	defer res.Body.Close()
	dec := json.NewDecoder(res.Body)
	out := &Cluster{}
	err = dec.Decode(out)
	if err != nil {
		return nil, err
	}
	return out, nil
}
883652
func (res *Resource) toManyHandler(w http.ResponseWriter, r *http.Request, storage store.ToMany) {
	id := pat.Param(r, "id")

	list, err := storage(r.Context(), id)
	if err != nil && reflect.ValueOf(err).IsNil() == false {
		SendHandler(w, r, err)
		return
	}

	SendHandler(w, r, list)
}
796025
func (c *UserController) Show(ctx *app.ShowUserContext) error {
	client, err := newAuthClient(ctx, c.config, c.httpOptions...)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	res, err := client.ShowUser(goasupport.ForwardContextRequestID(ctx), authservice.ShowUserPath(), ctx.IfModifiedSince, ctx.IfNoneMatch)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err": err.Error(),
		}, "unable to get user from the auth service")
		return jsonapi.JSONErrorResponse(ctx, errs.Wrap(err, "unable to get user from the auth service"))
	}
	defer rest.CloseResponse(res)

	switch res.StatusCode {
	case 200:
	// OK
	case 401:
		return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(rest.ReadBody(res.Body)))
	default:
		return jsonapi.JSONErrorResponse(ctx, errors.NewInternalError(ctx, errs.Errorf("status: %s, body: %s", res.Status, rest.ReadBody(res.Body))))
	}

	authUser, _ := client.DecodeUser(res)

	if c.InitTenant != nil {
		go func(ctx context.Context) {
			c.InitTenant(ctx)
		}(ctx)
	}
	return ctx.OK(convertToAppUser(authUser))
}
569024
func (res *Resource) deleteHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, storage store.Delete) {
	id := pat.Param(ctx, "id")

	err := storage(ctx, id)
	if err != nil && reflect.ValueOf(err).IsNil() == false {
		SendHandler(ctx, w, r, err)
		return
	}

	w.WriteHeader(http.StatusNoContent)
}
1127823
func (c *ResourceController) Show(ctx *app.ShowResourceContext) error {

	if !token.IsServiceAccount(ctx) {
		log.Error(ctx, map[string]interface{}{}, "Unable to read resource. Not a service account")
		return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError("not a service account"))
	}

	svc := c.app.ResourceService()
	res, err := svc.Read(ctx, ctx.ResourceID)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"resource_id": ctx.ResourceID,
		}, "unable to read resource")
		return jsonapi.JSONErrorResponse(ctx, err)
	}

	return ctx.OK(res)
}
222543
func (s *httpService) sumHandler(w http.ResponseWriter, req *http.Request) {
	// parse query parameters
	v := req.URL.Query()
	a, err := strconv.ParseInt(v.Get("a"), 10, 64)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	b, err := strconv.ParseInt(v.Get("b"), 10, 64)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	// call our Sum binding
	result, err := s.service.Sum(req.Context(), a, b)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	// return the result
	w.Write([]byte(fmt.Sprintf("%d", result)))
}
198988
func WithHandler(h ...Handler) Option {
	return func(o *Options) {
		o.Handlers = append(o.Handlers, h...)
	}
}
126157
func (r *Router) IndexHandler(w http.ResponseWriter, _ *http.Request, _ Params) {
	WriteJSON(w, r.Index())
}
812565
func HomeHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, `<!DOCTYPE html>
	<html lang="en">
	<head>
		<title>go-httpbin</title>
	<head>
	<body>
		<h1>go-httpbin</h1>
		<p>
			<a href="https://github.com/ahmetb/go-httpbin">
				Read documentation &rarr;
			</a>
	</body>
	</html>`)
}
776368
func HTMLHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html")
	fmt.Fprint(w, htmlData)
}
252752
func (res *Resource) relationshipHandler(
	resourceType string,
	handler http.HandlerFunc,
) {

	// handle /.../:id/<resourceType>
	matcher := fmt.Sprintf("%s/%s", patID, resourceType)
	res.HandleFunc(
		pat.Get(matcher),
		handler,
	)
	res.addRoute(get, matcher)

	// handle /.../:id/relationships/<resourceType>
	relationshipMatcher := fmt.Sprintf("%s/relationships/%s", patID, resourceType)
	res.HandleFunc(
		pat.Get(relationshipMatcher),
		handler,
	)
	res.addRoute(get, relationshipMatcher)
}
1289304
func MainHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	// For now it only supports `GET`
	if r.Method != "GET" {
		return errors.ErrGenericNotFound.WithDetail(nil)
	}

	if _, err := w.Write([]byte("{}")); err != nil {
		return errors.ErrUnknown.WithDetail(err)
	}
	return nil
}
523670
func QueryHandler(repo eh.ReadRepo) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.Method != "GET" {
			http.Error(w, "unsuported method: "+r.Method, http.StatusMethodNotAllowed)
			return
		}

		var (
			data interface{}
			err  error
		)
		// If there is a trailing slash in the URL we return all items,
		// otherwise we try to parse an ID from the last part to return one item.
		_, idStr := path.Split(r.URL.Path)
		if idStr == "" {
			if data, err = repo.FindAll(r.Context()); err != nil {
				http.Error(w, "could not find items: "+err.Error(), http.StatusInternalServerError)
				return
			}
		} else {
			id, err := uuid.Parse(idStr)
			if err != nil {
				http.Error(w, "could not parse ID: "+err.Error(), http.StatusBadRequest)
				return
			}

			if data, err = repo.Find(r.Context(), id); err != nil {
				if rrErr, ok := err.(eh.RepoError); ok && rrErr.Err == eh.ErrEntityNotFound {
					http.Error(w, "could not find item", http.StatusNotFound)
					return
				}

				http.Error(w, "could not find item: "+err.Error(), http.StatusInternalServerError)
				return
			}
		}

		b, err := json.Marshal(data)
		if err != nil {
			http.Error(w, "could not encode result: "+err.Error(), http.StatusInternalServerError)
			return
		}
		w.Write(b)
	})
}
1209735
func (t *Tango) UseHandler(handler http.Handler) {
	t.Use(WrapBefore(handler))
}