Skip to content
Advertisement

Tag: go

How to properly refuse websocket upgrade request?

Sometimes I want to refuse a http client’s request to upgrade connection to websocket. Code (using go’s Gin and gorilla/websocket framework:) To allow upgrade: To refuse upgrade (due to invalid request params): Explaination: Here to refuse the upgrade I just return a http 400 code, then terminate the connection, and didn’t do the upgrade at all. The issue The problem

How to read file from disk and pass it to WebAssembly using Go?

Specifically, how to connect <input type=”file”> with this function in Go? I know there is “syscall/js” package, but I didn’t find any examples with file reading. Answer I’ve wanted a satisfactory answer for this for years, finally figured it out the other night. You can essentially boil the whole thing down to: I wrote a little blog post about it

Assign Golang variable to Javascript

Currently I am having an issue related to assign a Golang variable to a Javascript variable. I am using the Golang templates, so, from the backend I sent a JSON variable, just like this: As you see, I have a slice, convert it to Json and then that Json to string, and send it to the template. Then, in the

Advertisement