Git Product home page Git Product logo

go-wasm-http-server's Introduction

Hi there ๐Ÿ‘‹

Check out some of my articles on dev.to and Medium.

Some of my talks (in french ๐Ÿ‡ซ๐Ÿ‡ท) are available on this Youtube playlist.

Cheers ๐Ÿป

go-wasm-http-server's People

Contributors

nlepage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

go-wasm-http-server's Issues

undefined: js.Wrapper

hi, trying to run the hello example.

In go-wasm-http-server/docs/hello

GOOS=js GOARCH=wasm go build -o api.wasm .

but i am stuck here:

../../response_recorder.go:19:10: undefined: js.Wrapper

Interesting stuff

Very cool project. I've been trying to figure out how to integrate wasm into github.com/micro/micro and I think you've given me some good ideas. Do you have an example demo running anywhere?

Add SSE

To allow service in client and server to push CDC updates when data sources change.

Create, Update, Delete are the ops.

namespace topic that maps to json fragment is the scope of the payload.

client will then update cache of json using that scope.

later when templates are introduced these can also be pushed. Just need CDC on server file system. At the moment html templates are not used. Scoping it a xml scope instead of json obviously.

"res.(http.Flusher).Flush()" not work

when use golang direct run,it's perfect:
https://user-images.githubusercontent.com/342509/128476357-3f6f97de-7f09-4b16-97b7-39571450390c.mov

package main

import (
	"fmt"
	"net/http"
	"time"
)

func main() {
http.HandleFunc("/wawawa",  func(res http.ResponseWriter, req *http.Request) {
	flusher := res.(http.Flusher)
	res.Header().Set("Content-Type", "text/html")
	fmt.Fprintf(res, "<!doctype html>\n<html><head><title>test</title></head><body>")
	for i := 1; i <= 50; i++ {
		fmt.Fprintf(res, "<p>Chunk #%d</p>\n<script>console.log(new Date())</script>\n", i)
		// perfect
		flusher.Flush()
		time.Sleep(500 * time.Millisecond)
	}
	fmt.Fprintf(res, "</body>\n</html>")
})

	http.ListenAndServe(":8080", nil)

	select {}
}

but with wasm, it's not work:
https://user-images.githubusercontent.com/342509/128476360-f9d80484-c6e4-4bb8-805d-5fc4273727e2.mov

package main

import (
	"fmt"
	"net/http"
	"time"
	wasmhttp "github.com/nlepage/go-wasm-http-server"
)

func main() {
	http.HandleFunc("/wawawa",  func(res http.ResponseWriter, req *http.Request) {
		flusher := res.(http.Flusher)
		res.Header().Set("Content-Type", "text/html")
		fmt.Fprintf(res, "<!doctype html>\n<html><head><title>test</title></head><body>")
		for i := 1; i <= 50; i++ {
			fmt.Fprintf(res, "<p>Chunk #%d</p>\n<script>console.log(new Date())</script>\n", i)
			// not work, 25 s later
			flusher.Flush()
			time.Sleep(500 * time.Millisecond)
		}
		fmt.Fprintf(res, "</body>\n</html>")
	})

	wasmhttp.Serve(nil)

	select {}
}

Query

This looks interesting! Just want to make sure I comprehend what it does before diving in.

Suppose I have an application that calls a third party JS library function that expects to fetch a file from a server, say,

MidiJS.play(URL) // where the server at URL generates and returns a midi file to be played

Can I use go-wasm-http-server in a Go wasm app that generates the midi file content locally in the user's browser to provide a pseudo URL that returns the generated content to the JS call?

Pass through to server and SSR

Really cleanly done @nlepage

If your interested I will be adding the following:

  1. pass through so that Service side rendering can occur for SEO.
  2. Detection of search engine.
  3. Data calls in examples
  4. Caching and hashing of data.
  5. Data push so that server can invalidate cache using CDC ( change data capture )
  6. Security . So that certain views are guarded.
  7. Web push notifications. Apple now fully supports it as of a few days ago

Pleas feel free to comment.

run go server in docker wasm container

Is your feature request related to a problem?
run go server build with tiny go in docker wasm container

Describe the solution you'd like
Hi, i found this article about how to run wasm docker with a rust server example:
docker-wasm-technical-preview
I would like to run a go server in a wasm container so i found your package
but i can't make a wasm server with go working in a wasm container
do you know how i can do this or if it's possible ?
Thanks

step to reproduce:

first we need to install docker preview version from documentation

main.go

package main

import (
	"encoding/json"
	"fmt"
	"net/http"

	wasmhttp "github.com/nlepage/go-wasm-http-server"
)

func main() {
	http.HandleFunc("/hello", func(res http.ResponseWriter, req *http.Request) {
		params := make(map[string]string)
		if err := json.NewDecoder(req.Body).Decode(&params); err != nil {
			panic(err)
		}

		res.Header().Add("Content-Type", "application/json")
		if err := json.NewEncoder(res).Encode(map[string]string{
			"message": fmt.Sprintf("Hello %s!", params["name"]),
		}); err != nil {
			panic(err)
		}
	})

	wasmhttp.Serve(nil)

	select {}
}

build command

tinygo build -o main.wasm -target=wasi main.go

Dockerfile

FROM scratch
COPY main.wasm /main.wasm
EXPOSE 80
ENTRYPOINT [ "main.wasm" ]

build image command

docker buildx build --platform wasi/wasm32 -t go-http .

if you get an error uninstall docker and reinstall preview version from documentation

run container command

docker run -dp 80:80 --name=go-http --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm32 go-http

Cannot use hello example

I have the files used in the /docs/hello folder.

api.go
index.html
sw.js

Using the prebuilt wasm from the folder works, but if I try to build the Go source code:

GOOS=js GOARCH=wasm go build -o api.wasm .

The example does not alert you.
Also, if it helps:

  • I installed the go-wasm-http-server library with go get
  • My go version is go version go1.13.8 linux/amd64

Tinygo

Try tinygo to reduce overhead.

Json works but not gob encoding btw.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.