151 questions
1
vote
2
answers
82
views
Echo Golang render content and change url path without reloading layout page
I am trying to build a SPA.
There are some requirements I am desperately trying to achieve.
I have an index.html file as a layout which has some templates defined. The rendering of that works as ...
1
vote
1
answer
96
views
How does .Static function works in Echo for Go
I have been dealing with an issue with the static files in the application I'm building in go using Echo framework, I can not get the files to load, I only get 404 for the static files.
I have this in ...
1
vote
0
answers
105
views
Echo response issue with Templ ( Golang )
Echo & Templ Response Issue
I am trying to build an admin dashboard for my project using Echo V5 & Templ.
My current setup
// RegisterRoutes -> a route registeration method used to ...
1
vote
0
answers
345
views
How to use templ in conjunction with the Echo framework?
I'm planning use templ library like this github.com/a-h/templ v0.2.707
but there is problem where rendering html
first will show you my code written so far:
go.mod
module cozy
go 1.21.6
require (
...
1
vote
2
answers
917
views
Issues with JWT Middleware in Echo and oapi-codegen Application Causing Multiple 401 Responses
I'm working on an Echo-based Go application where I'm using JWT for authentication. I've integrated the echo-jwt middleware and oapi-codegen for OpenAPI validation. However, I'm facing issues where ...
2
votes
0
answers
867
views
Use a custom logger, with go echo framework
i am trying to apply a format to my loggin, with request specific details in the format. EX: when i log "Test log" I should expected to be logged like:
2024-06-22T19:36:48+01:00 INFO [...
2
votes
0
answers
114
views
Byte array transfer through echo framework to JS blob
I'm trying to pass the result of a google text to speech api SynthesizeSpeech.audio_content to frontend throught echo framework (golang).
resp, err := client.SynthesizeSpeech(c.ctx, &req)
if err !=...
1
vote
0
answers
592
views
Problems with static files Go-Echo-Templ
I am starting a Go project using Echo and Templ.
I have a project structure as follows:
/
/cmd
main.go
/static
css
style.css
/view
/layout
base.templ
The problem I am ...
1
vote
0
answers
790
views
Go labstack/echo and OpenTelemetry doesn't work
I'm trying to add otel tracing to my Echo server. I'm basing my code on example but anything is not coming from application to Jaeger instance that i'm running locally.
First, I've injected the ...
3
votes
0
answers
1k
views
How to Ensure Required Fields Presence and Validate HTTP Request with Echo Framework?
Is there a anyway to validate if a field is present in a http request with the echo framwork?
Lets take this code for example:
type ExampleStruct struct {
Name string `json:"name"`
...
1
vote
1
answer
836
views
Go framework Echo middleware usage
In my main function I have used the go framework echo to create a Logger and Recover
func main() {
db := initDB("storage.db")
migrate(db)
e := echo.New()
-> e.Use(...
-2
votes
1
answer
615
views
echo: http: panic serving [::1]:45724: runtime error: invalid memory address or nil pointer dereference goroutine 10 [running]:
im trying to create an rest api with go/echo and postgres with raw sql but i cant make it work, no idea whats the problem
the console prints the text in the title
recipe.go
func CreateRecipe(recipe *...
1
vote
1
answer
290
views
How to pass param from middleware to controller
I am building a web API with Echo Labstack framework. I have a middleware in my route to check for user authentication, but then I am having difficulty in passing the data to controller and could not ...
2
votes
1
answer
41
views
Form variables not available in testing
I am a Go newbie. I have written an API server built on the Echo server, using the DeepMap OpenAPI generator and Postgres using pgxpool. It is working well enough and has been in use for a year, but ...
1
vote
0
answers
92
views
Resume a download when Echo server is restarted
I'm trying to make a proxy to download server files with an authentication layer.
I'm using Golang (1.21.0) and Echo (4.11.1)
Problem description
When a user is downloading a big file, if I kill the ...
3
votes
2
answers
1k
views
I want to Serve React App with react router dom with echo
I want to Serve React App with react router dom with echo in Go. But I'm facing a problem in routing because if I directly go to that route I get not found error
package main
import (
"fmt&...
1
vote
2
answers
5k
views
Golang Echo bind path param and json body separately
I am using Echo web framework in Golang and I wrote this code
package main
import (
"github.com/labstack/echo/v4"
"net/http"
)
type ProjectPath struct {
ID string `...
1
vote
0
answers
345
views
How to configure middleware to skip dynamic route
I'm using echo-labstack and I'm implementing a JWT validation. I'd like the validating route to be unprotected by the JWT middleware but the route is a route like '/validate/:token'.
Is there a way to ...
2
votes
2
answers
3k
views
Serving static files with echo middleware and embed
project folder
->templates
->t.tmpl
->examples
->html
->blocks
->...
->assets
->...
->index.html
im t.tmpl there is call to <link rel="...
1
vote
1
answer
1k
views
Long running task (return handler function and continue executing code in goroutine)
I am building a REST API in golang using Echo. I have a handler function Temp that handles a Post request with some form-data.
func NewBatchHandler(e *echo.Echo, us domain.BatchUsecase) {
handler :...
-1
votes
1
answer
248
views
Can 2 fields in struct have same struct tags in Go
I have Struct Type for binding SQL data to my struct variable.
It has 2 Feilds as CenterCode and ActualCenterCode
type LearnerModel struct {
CenterCode dbr.NullString `json:"centerCode" ...
1
vote
1
answer
246
views
Send uploaded file
I use echo framework for building REST API.
I receive file via http request and i need to send it to the next API service by post request.
How i can do this without storing file?
I've tried this way, ...
1
vote
0
answers
347
views
Docker container can't connect to a Golang Echo Server running on host machine
I have a Golang Echo Server running on port 5050 using windows WSL. I can talk to the server perfectly fine from browser and through curl in a WSL terminal.
// Start server
go func() {
...
1
vote
1
answer
318
views
Appending to an existing list via http request
I'm in the process of making a simple REST API using Echo. I have a variable which is the following map, based on this struct I've made:
type Checklist struct {
ID int `json:&...
1
vote
1
answer
1k
views
Echo framework binding request data to Option[T] monad
Let's say I have a REST API implemented with Golang Echo framework. I want to have a way to use optional query parameters in request.
I want to use a Option[T] monad from samber/mo library.
For ...
0
votes
1
answer
273
views
Unit testing a HTTP handler that returns a stream of multiple files
HTTP handler
I have a HTTP handler like this:
func RouteHandler(c echo.Context) error {
outs := make([]io.Reader, 5)
for i := range outs {
outs[i] = // ... comes from a logic.
}
...
1
vote
0
answers
443
views
GoCV start & stop webcam recording with 2 differents API calls
I am trying to design a small backend service in Go with the Echo library to record video from a webcam using GoCV.
I would like to make a call to start the recording and one to stop it, whereas from ...
1
vote
0
answers
490
views
How to Handle Dynamic Database Connections in Go?
I am currently building a Go application that needs to connect to multiple databases dynamically.
For context I have 22 Databases (db1, db2, db3...) and the dbUser, dbPass and dbPort remains the same. ...
1
vote
1
answer
1k
views
Context in echo v4
When I made a request with context
req, err := http.NewRequestWithContext(ctx, method, url, payload)
Then, if I check the context in the service I can see the context I've sent. For example, in an ...
1
vote
0
answers
646
views
Echo golang - issue with Swagger example values
I have ECHO server on GO and assigned on it Swagger.
If I'm using the structure which is on the same package (file) then example values are working well, ex:
type Test struct {
TestField string `...
-1
votes
1
answer
3k
views
Golang Get all POST Form data using PostParams and get values as string
I want to get all the post form data and get the values as string, however using PostParams I am able to get all the post data, but the values are as array key: [value], how can I get all the form ...
1
vote
1
answer
504
views
how to create dinamic port in golang (echo framwork)
i have package config.go in this my code
package config
import (
"fmt"
logger "github.com/sirupsen/logrus"
"gorm.io/driver/postgres"
"gorm.io/gorm&...
1
vote
1
answer
6k
views
error: json: unsupported type: func() time.Time in Golang
i am new in golang, just try some API in Echo Framework and got some error.
My Models :
package models
import (
"net/http"
"quotes/db"
)
type Quote struct {
Id ...
1
vote
0
answers
254
views
Is there a way to assign result from rendering template echo framework
How I can assign result from rendering template to send this value as json, for ajax call
my example:
func Load(c echo.Context) error {
params := map[string]any{
"btn_style": &...
2
votes
2
answers
582
views
How to prevent "+" from escaping in go-echo
I am using https://github.com/labstack/echo in one of the projects. I am using c.QueryParam to parse the query parameter and its values. One of the values contains a + symbol in it and it converts ...
3
votes
0
answers
482
views
Limit route groups HTTP methods in Echo
I'm using groups in Echo to pack some routes with a common prefix but when I get the list of routes, it returns routes for all HTTP methods.
main.go
e := echo.New()
adminGroup := e.Group("/admin&...
2
votes
0
answers
376
views
File download status and connection abortion using Golang and Echo
I'm currently trying to use a golang and echo app as both a web server and a reverse proxy and running into some issues.
The main goal of this app is to allow a client to download files of various ...
0
votes
1
answer
149
views
How can i change the Delim in echo Render?
i am trying to change the delimiter for go in an html template. Unfortunately, it does not work in the render function, nor in the main function.
See https://pkg.go.dev/text/template#Template.Delims
...
2
votes
1
answer
2k
views
How can i use a json object in golang template
My goal is to load an object from the database as a json object into a vue application that is rendered in a golang template. The data should be loaded directly into the web page. Does anyone have an ...
5
votes
1
answer
7k
views
How to Add/Set Header after next() in Golang Echo Middleware?
Main Purpose:
I want to simply count the execution time for any API / route, and add it into the Response Header with key: ExecutionTime.
I am very open to another alternative, since my method may ...
1
vote
1
answer
658
views
Partial update a structure with echo and gorm
I got a user interface, user model and user id structures
type UserId struct {
Id int64 `param:"id" json:"id"`
}
type User struct {
Email string `json:"email&...
0
votes
1
answer
609
views
How to handle SPA urls correctly in Golang?
I am trying to embed and serve my frontend (nextjs with static export) with echo. I am currently using:
//go:embed all:frontend/out
var FrontendFS embed.FS
func BuildFrontendFS() http.FileSystem {
...
2
votes
0
answers
495
views
How can I redirect from a middleware in go?
I have the following case.
how can i address from handlev1 to handle2, using middleware?
that depends on IsActiveBypass
Or what do you suggest?
func Handlev1(sw echoswagger.ApiRoot, itemUseCase ...
2
votes
1
answer
2k
views
Golang Echo Labstack How to Call a Function / Method in a Template View
I am building a front end website with Golang Echo Labstack framework, and I want to call some custom functions in my template view. How do I do this with Echo?
For example, I am able to do this with ...
3
votes
1
answer
4k
views
Golang - Binding Headers in echo api
Golang - Binding Headers in echo api
I'm trying to bind headers to struct. So far I did the same as in documentation here but it looks like doesn't work at all. I checked in debugger incoming request ...
2
votes
2
answers
2k
views
Go Echo: POST Method gives Error "Method not allowed"
Building an app with echo and basically created some routes.
The GET ones are working fine, but the post one is give me the error:
Do not really understand where the error lies here.
{...."method&...
0
votes
1
answer
308
views
How to put meaningful custom status text for custom status codes in Go's echo framework?
func (api *API) sendResponse(c echo.Context, ...) error {
...
if ok {
if evt.Error != nil {
return c.JSONBlob(statuscodes.HttpStatusDiagnosticsCheckError, resBytes)
...
0
votes
2
answers
674
views
How to strconv in echo c.param?
Could anyone advise how to overcome this problem please ?
func GetUserController(c echo.Context) error {
id := c.Param("id")
finduser := users[id]
return c.JSON(http.StatusOK,...
1
vote
1
answer
2k
views
Inject headers into httptest.Recorder so echo context can see them in Golang
I have some tests that inject headers into Echo like this:
func test() {
request := httptest.NewRequest(http.MethodGet, "/", http.NoBody)
recorder := httptest.NewRecorder()
...
0
votes
2
answers
436
views
when using fmt.Printf() many blanks are displayed
I'm trying to complete an echo server using golang.
server like this:
// use tcp to echo time
func main() {
// listen tcp localhost:8000
listener, err := net.Listen("tcp", "...