mirror of
https://github.com/foomo/foomo-docs.git
synced 2025-10-16 12:35:40 +00:00
feat: playground go iteration
This commit is contained in:
parent
d33307238e
commit
9375533f1c
@ -25,6 +25,7 @@
|
||||
"prism-react-renderer": "^1.2.1",
|
||||
"react": "^17.0.1",
|
||||
"react-dom": "^17.0.1",
|
||||
"react-full-screen": "^1.1.0",
|
||||
"url-loader": "^4.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -1,16 +1,111 @@
|
||||
import React from "react";
|
||||
import { useCallback } from "react";
|
||||
import { FullScreen, useFullScreenHandle } from "react-full-screen";
|
||||
|
||||
// function App() {
|
||||
|
||||
// return (
|
||||
// <div>
|
||||
// <button onClick={}>Enter fullscreen</button>
|
||||
|
||||
// <FullScreen handle={handle}>Any fullscreen content here</FullScreen>
|
||||
// </div>
|
||||
// );
|
||||
// }
|
||||
|
||||
// export default App;
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Iframe } from "./Iframe";
|
||||
import { IsItCool } from "./IsItCool";
|
||||
|
||||
import Highlight, { defaultProps } from "prism-react-renderer";
|
||||
import Link from "@docusaurus/Link";
|
||||
|
||||
//src={"https://play.golang.org/p/" + props.id}
|
||||
|
||||
export const GoPlayground = (props: { id: string; proportion: number }) => {
|
||||
const [interactive, setInteractive] = useState(false);
|
||||
const [source, setSource] = useState("");
|
||||
const handle = useFullScreenHandle();
|
||||
useEffect(() => {
|
||||
if (source == "" && props.id !== "") {
|
||||
fetch("http://localhost:8080/?id=" + props.id, {
|
||||
mode: "cors",
|
||||
})
|
||||
.then((res) =>
|
||||
res
|
||||
.json()
|
||||
.then((data) => setSource(data.code))
|
||||
.catch((e) => setSource("parse json"))
|
||||
)
|
||||
.catch((e) => setSource("can not load source yet"));
|
||||
}
|
||||
}, [source]);
|
||||
const href = "https://goplay.tools/snippet/" + props.id;
|
||||
return (
|
||||
<IsItCool topic="load external go playground, with all it´s potentially evil cookies coming from https://goplay.tools" id="goPlaygroundIsCool">
|
||||
<Iframe
|
||||
src={"https://goplay.tools/snippet/" + props.id}
|
||||
proportion={props.proportion}
|
||||
/>
|
||||
<>
|
||||
<div style={{ paddingBottom: "1rem", width: "100%" }}>
|
||||
{interactive ? (
|
||||
<>
|
||||
<button
|
||||
className={"button button--primary"}
|
||||
onClick={(_e) => {
|
||||
setInteractive(false);
|
||||
}}
|
||||
>
|
||||
close playground
|
||||
</button>{" "}
|
||||
<button
|
||||
className={
|
||||
"button button--primary" + (interactive ? "" : " disabled")
|
||||
}
|
||||
onClick={(_e) => {
|
||||
handle.enter();
|
||||
}}
|
||||
>
|
||||
fullscreen
|
||||
</button>{" "}
|
||||
</>
|
||||
) : (
|
||||
<button
|
||||
className={"button button--primary"}
|
||||
onClick={(_e) => {
|
||||
setInteractive(true);
|
||||
}}
|
||||
>
|
||||
open playground
|
||||
</button>
|
||||
)}{" "}
|
||||
<Link href={href}>go to {href}</Link>
|
||||
</div>
|
||||
{!interactive && (
|
||||
<Highlight {...defaultProps} code={source} language="go">
|
||||
{({ className, style, tokens, getLineProps, getTokenProps }) => (
|
||||
<pre className={className} style={style}>
|
||||
{source == "" ? "... loading sources" : ""}
|
||||
{tokens.map((line, i) => (
|
||||
<div {...getLineProps({ line, key: i })}>
|
||||
{line.map((token, key) => (
|
||||
<span {...getTokenProps({ token, key })} />
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</pre>
|
||||
)}
|
||||
</Highlight>
|
||||
)}
|
||||
<div style={{ display: interactive ? "block" : "none" }}>
|
||||
<IsItCool
|
||||
topic="load external go playground, with all it´s potentially evil cookies coming from https://goplay.tools"
|
||||
id="goPlaygroundIsCool"
|
||||
>
|
||||
<div>
|
||||
<FullScreen handle={handle}>
|
||||
<Iframe src={href} proportion={props.proportion} />
|
||||
</FullScreen>
|
||||
</div>
|
||||
</IsItCool>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@ -4857,6 +4857,11 @@ fs.realpath@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
|
||||
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=
|
||||
|
||||
fscreen@^1.0.2:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/fscreen/-/fscreen-1.2.0.tgz#1a8c88e06bc16a07b473ad96196fb06d6657f59e"
|
||||
integrity sha512-hlq4+BU0hlPmwsFjwGGzZ+OZ9N/wq9Ljg/sq3pX+2CD7hrJsX9tJgWWK/wiNTFM212CLHWhicOoqwXyZGGetJg==
|
||||
|
||||
fsevents@~2.3.2:
|
||||
version "2.3.2"
|
||||
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
|
||||
@ -7224,6 +7229,13 @@ react-fast-compare@^3.1.1:
|
||||
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.0.tgz#641a9da81b6a6320f270e89724fb45a0b39e43bb"
|
||||
integrity sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA==
|
||||
|
||||
react-full-screen@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/react-full-screen/-/react-full-screen-1.1.0.tgz#696c586da25652ed10d88046f8dc0b6620f4ef96"
|
||||
integrity sha512-ivL/HrcfHhEUJWmgoiDKP7Xfy127LGz9x3VnwVxljJ0ky1D1YqJmXjhxnuEhfqT3yociJy/HCk9/yyJ3HEAjaw==
|
||||
dependencies:
|
||||
fscreen "^1.0.2"
|
||||
|
||||
react-helmet@^6.1.0:
|
||||
version "6.1.0"
|
||||
resolved "https://registry.yarnpkg.com/react-helmet/-/react-helmet-6.1.0.tgz#a750d5165cb13cf213e44747502652e794468726"
|
||||
|
||||
62
go.mod
Normal file
62
go.mod
Normal file
@ -0,0 +1,62 @@
|
||||
module github.com/foomo/foomo-docs
|
||||
|
||||
go 1.17
|
||||
|
||||
require github.com/foomo/keel v0.5.2
|
||||
|
||||
require (
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/magiconair/properties v1.8.5 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||
github.com/mitchellh/mapstructure v1.4.3 // indirect
|
||||
github.com/pelletier/go-toml v1.9.4 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/prometheus/client_golang v1.11.0 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.26.0 // indirect
|
||||
github.com/prometheus/procfs v0.6.0 // indirect
|
||||
github.com/shirou/gopsutil v2.20.9+incompatible // indirect
|
||||
github.com/spf13/afero v1.6.0 // indirect
|
||||
github.com/spf13/cast v1.4.1 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/spf13/viper v1.10.1 // indirect
|
||||
github.com/subosito/gotenv v1.2.0 // indirect
|
||||
go.opentelemetry.io/contrib v0.20.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/host v0.20.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/metric/prometheus v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/stdout v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/export/metric v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/metric v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v0.20.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v0.7.0 // indirect
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
go.uber.org/zap v1.19.1 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
|
||||
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
|
||||
google.golang.org/grpc v1.43.0 // indirect
|
||||
google.golang.org/protobuf v1.27.1 // indirect
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
51
playgroundserver/main.go
Normal file
51
playgroundserver/main.go
Normal file
@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/foomo/keel"
|
||||
)
|
||||
|
||||
func main() {
|
||||
svr := keel.NewServer(
|
||||
keel.WithHTTPZapService(true),
|
||||
keel.WithHTTPViperService(true),
|
||||
keel.WithHTTPPrometheusService(true),
|
||||
)
|
||||
|
||||
l := svr.Logger()
|
||||
|
||||
svs := newService()
|
||||
|
||||
svr.AddService(
|
||||
keel.NewServiceHTTP(l, "demo", ":8080", svs),
|
||||
)
|
||||
|
||||
svr.Run()
|
||||
}
|
||||
|
||||
func newService() *http.ServeMux {
|
||||
s := http.NewServeMux()
|
||||
s.HandleFunc("/", serve)
|
||||
return s
|
||||
}
|
||||
|
||||
func serve(w http.ResponseWriter, r *http.Request) {
|
||||
//http.ListenAndServe(":3001", http.HandlerFunc(
|
||||
|
||||
id := r.URL.Query().Get("id")
|
||||
if id == "" {
|
||||
http.Error(w, "no id get param given", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
resp, err := http.Get("https://goplay.tools/api/snippet/" + id)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
io.Copy(w, resp.Body)
|
||||
resp.Body.Close()
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user