Last active
May 17, 2020 16:36
-
-
Save notjames/7bd2d87a691a8bc9d7a2539772b93ad3 to your computer and use it in GitHub Desktop.
golang: creating an instance requiring interface parameters...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sigh. totally misread the docs.