Skip to content
Discussion options

You must be logged in to vote

You can get image name and tag by registering route with path variable and cut it in handler

package main

import (
	"errors"
	"fmt"
	"log/slog"
	"net/http"
	"strings"

	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
)

func main() {
	e := echo.New()
	e.Use(middleware.RequestLogger())
	e.Use(middleware.Recover())

	e.GET(`/foo/:tag`, func(c echo.Context) error {
		before, after, ok := strings.Cut(c.Param(`tag`), ":")
		if !ok {
			return errors.New("path does not contain colon")
		}
		return c.JSON(http.StatusOK, map[string]string{
			"before": before,
			"after":  after,
		})
	})

	e.GET(`/foo/bar/baz\:latest`, func(c echo.Context) error {
		return c.String(http.S…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@aceeric
Comment options

Answer selected by aceeric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants