govuk-frontend-go

module
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT

README

govuk-frontend-go

Release CI Go Reference License

GOV.UK Design System integration for Go, with a Gin adapter.

It provides:

  • Versioned GOV.UK Frontend assets
  • Go template helpers and component renderers
  • Gin integration for serving assets and rendering templates
  • A coverage matrix

Add the module to your service:

go get github.com/0xnu/govuk-frontend-go@<version-tag>

Minimal setup:

package main

import (
	"net/http"
	"os"

	"github.com/gin-gonic/gin"

	govukgin "github.com/0xnu/govuk-frontend-go/pkg/govuk/gin"
	govuktemplate "github.com/0xnu/govuk-frontend-go/pkg/govuk/template"
)

func main() {
	r := gin.Default()

	t, err := govuktemplate.Parse()
	if err != nil {
		panic(err)
	}
	r.SetHTMLTemplate(t)

	g := govukgin.New()
	if err := g.SetGovUKFrontendVersion("6.3.0"); err != nil {
		panic(err)
	}
	g.Mount(r)

	r.GET("/", handleIndex)

	addr := os.Getenv("ADDR")
	if addr == "" {
		addr = ":9194"
	}

	if err := r.Run(addr); err != nil {
		panic(err)
	}
}

func handleIndex(c *gin.Context) {
	c.HTML(http.StatusOK, "page", gin.H{
		"ServiceName": "Example service",
	})
}

What this gives you:

  • Templates embedded and loaded via pkg/govuk/template (source templates live under internal/govuk/templates)
  • Embedded assets mounted at:
    • GET /assets/*
    • GET /favicon.ico

Coverage:

  • Components and patterns implemented in this module are listed in here.

Versioning:

  • Prefer a tag (e.g. @v6.4.0) rather than @main.
  • Embedded GOV.UK Frontend assets are shipped for: 6.3.0, 6.4.0 (and current defaults to the latest bundled version).

Select the GOV.UK Frontend version you want to serve:

g := govukgin.New()
if err := g.SetGovUKFrontendVersion("6.4.0"); err != nil {
	panic(err)
}
g.Mount(r)

Quickstart

go run ./cmd/example-gin-app

## OR ##

make example
  • Home page: http://localhost:9194/

License

This project is licensed under the MIT License.

(c) 2026 Finbarrs Oketunji. All Rights Reserved.

govuk-frontend-go is Licensed under the Open Government Licence v3.0

Directories

Path Synopsis
cmd
example-gin-app command
internal
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL