Skip to content

Instantly share code, notes, and snippets.

@notjames
Last active May 17, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notjames/7bd2d87a691a8bc9d7a2539772b93ad3 to your computer and use it in GitHub Desktop.
Save notjames/7bd2d87a691a8bc9d7a2539772b93ad3 to your computer and use it in GitHub Desktop.
golang: creating an instance requiring interface parameters...
package mypackage
import (
"net/http"
"github.com/gobuffalo/buffalo"
gateway "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/api"
"google.golang.org/grpc/status"
)
type PromRequest struct {
Endpoint string `json:"endpoint,omitempty"`
Query string `json:"query:omitempty"`
TimeRange string `json:"timerange:omitempty"`
}
func getMetric(pr PromRequest) (*queryData, error) {
apiConfig := api.Config{Address: pr.Endpoint}
promapi := api.NewClient(apiConfig)
}
func MetricsHandler(c buffalo.Context) error {
var pr PromRequest
var qd queryData
endpoint := "http://myendpoint.domain.com/api/v1/"
pr.Endpoint = endpoint
pr.Query = c.Param("query")
pr.TimeRange = c.Param("timerange")
qd, err := getMetric(pr)
if err != nil {
return c.Error(gateway.HTTPStatusFromCode(status.Convert(err).Code()), errors.WithStack(err))
}
return c.Render(http.StatusOK, r.JSON(qd))
}
@notjames
Copy link
Author

sigh. totally misread the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment