Skip to content

Commit 5cbaf74

Browse files
Cors/version (#270)
* Enable CORS for version information * Enable CORS for version information * Add middleware to version endpoint * Refactor version into GQL * tidy
1 parent 14fa645 commit 5cbaf74

File tree

8 files changed

+78
-50
lines changed

8 files changed

+78
-50
lines changed

generated.go

Lines changed: 64 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/getsentry/sentry-go v0.13.0
1212
github.com/go-chi/chi v3.3.2+incompatible
1313
github.com/go-chi/httplog v0.2.5
14-
github.com/go-chi/render v1.0.1
1514
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
1615
github.com/google/uuid v1.3.0
1716
github.com/gorilla/mux v1.8.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
210210
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
211211
github.com/go-chi/httplog v0.2.5 h1:S02eG9NTrB/9kk3Q3RA3F6CR2b+v8WzB8IxK+zq3dBo=
212212
github.com/go-chi/httplog v0.2.5/go.mod h1:/pIXuFSrOdc5heKIJRA5Q2mW7cZCI2RySqFZNFoZjKg=
213-
github.com/go-chi/render v1.0.1 h1:4/5tis2cKaNdnv9zFLfXzcquC9HbeZgCnxGnKrltBS8=
214-
github.com/go-chi/render v1.0.1/go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1OvJns=
215213
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
216214
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
217215
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=

model/models_gen.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resolver.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/dapperlabs/flow-playground-api/controller"
2828
userErr "github.com/dapperlabs/flow-playground-api/middleware/errors"
2929
"github.com/dapperlabs/flow-playground-api/model"
30+
"github.com/dapperlabs/flow-playground-api/server/version"
3031
"github.com/dapperlabs/flow-playground-api/storage"
3132
"github.com/google/uuid"
3233
"github.com/onflow/cadence"
@@ -399,9 +400,15 @@ func (r *projectResolver) UpdatedAt(_ context.Context, proj *model.Project) (str
399400
type queryResolver struct{ *Resolver }
400401

401402
func (r *queryResolver) PlaygroundInfo(_ context.Context) (*model.PlaygroundInfo, error) {
403+
emulatorVer, err := version.GetDependencyVersion("github.com/onflow/flow-emulator")
404+
if err != nil {
405+
return nil, err
406+
}
407+
402408
return &model.PlaygroundInfo{
403-
APIVersion: *r.version,
404-
CadenceVersion: *semver.MustParse(cadence.Version),
409+
APIVersion: *r.version,
410+
CadenceVersion: *semver.MustParse(cadence.Version),
411+
EmulatorVersion: *semver.MustParse(emulatorVer),
405412
}, nil
406413
}
407414

schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ scalar Version
55
type PlaygroundInfo {
66
apiVersion: Version!
77
cadenceVersion: Version!
8+
emulatorVersion: Version!
89
}
910

1011
type Project {

server/server.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"fmt"
2424
"github.com/dapperlabs/flow-playground-api/server/config"
2525
"github.com/dapperlabs/flow-playground-api/server/ping"
26-
"github.com/dapperlabs/flow-playground-api/server/version"
2726
"github.com/dapperlabs/flow-playground-api/telemetry"
2827
"github.com/prometheus/client_golang/prometheus/promhttp"
2928
"go.opentelemetry.io/otel/sdk/trace"
@@ -179,14 +178,11 @@ func main() {
179178
errors.Middleware(entry, localHub),
180179
),
181180
)
182-
183181
})
184182

185183
embedsHandler := controller.NewEmbedsHandler(store, conf.PlaygroundBaseURL)
186184
router.Handle("/embed", embedsHandler)
187185

188-
router.HandleFunc("/version", version.Handler)
189-
190186
err := ping.SetPingHandlers(store.Ping)
191187
if err != nil {
192188
log.Fatal(err)

server/version/version.go

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,54 +20,18 @@ package version
2020

2121
import (
2222
"errors"
23-
"fmt"
24-
"github.com/Masterminds/semver"
25-
"github.com/dapperlabs/flow-playground-api/build"
26-
"github.com/go-chi/render"
2723
"github.com/icza/bitio"
28-
"github.com/onflow/cadence"
29-
"net/http"
3024
"runtime/debug"
3125
)
3226

33-
func Handler(w http.ResponseWriter, r *http.Request) {
34-
version := struct {
35-
API string
36-
Cadence string
37-
Emulator string
38-
}{
39-
API: "n/a",
40-
Cadence: "n/a",
41-
Emulator: "n/a",
42-
}
43-
44-
apiVer := build.Version()
45-
if apiVer != nil {
46-
version.API = apiVer.String()
47-
}
48-
49-
cadenceVer := semver.MustParse(cadence.Version)
50-
if cadenceVer != nil {
51-
version.Cadence = cadenceVer.String()
52-
}
53-
54-
emulatorVer, err := getDependencyVersion("github.com/onflow/flow-emulator")
55-
if err == nil {
56-
version.Emulator = semver.MustParse(emulatorVer).String()
57-
}
58-
59-
render.JSON(w, r, version)
60-
}
61-
62-
func getDependencyVersion(path string) (string, error) {
27+
func GetDependencyVersion(path string) (string, error) {
6328
_ = bitio.NewReader
6429
bi, ok := debug.ReadBuildInfo()
6530
if !ok {
6631
return "", errors.New("failed to read build info")
6732
}
6833

6934
for _, dep := range bi.Deps {
70-
fmt.Printf("Dep: %+v\n", dep)
7135
if dep.Path == path {
7236
return dep.Version, nil
7337
}

0 commit comments

Comments
 (0)