Skip to content
Advertisement

Tag: go

How to use node modules (i.e: Sentry) on html template files served from Golang (gin-gonic package)

TL;DR: I have a Golang application that, using gin-gonics package, renders a very simple HTML . Once launched in local, accessing to http://localhost:8080/login (the URL is an example), it will show the html page, with its divs, buttons, etc. The html content is retrieved from a “.tpl” file. Problem is that such html page must include a javascript script, that

Failed to load module script: Expected a JavaScript module

I am using vite as build tool for my react app and golang as backend. I built the app for production and host the app on my http server. my directory structure: To host my files the code looks like (inside main.go) in index.html The code did actually send correct files but with wrong headers. Answer So I had to

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

CORS on golang server & javascript fetch frontend

I have a golang HTTP server with code like: I call this HTTP endpoint from a JS frontend, a react app deployed on port 3000, using code: The above code fails with the following logs. On the server side: On the browser, in the developer tools logs: Can someone help fix the authentication problem ? I am not sure if

Javascript websockets closing immediately after opening

The connection to the server is established and an alert is displayed for Connection open! However immediately afterwards the connection closes. The server does not call close and there seem to be no other errors in the console. This is happening in both chrome and firefox. I looked at a bunch of different similar examples on the web but to

Advertisement