The SEO library facilitates the optimization of Search Engine results by managing and injecting dynamic data into HTML tags.


Initialize a Collection instance. The Collection manages all the registered models and hold global seo settings

collection := seo.NewCollection()

// Turn off the default inherit the upper level SEO data when the current SEO data is missing

Register models to SEO

// Register mutiple SEO by name
collection.RegisterSEOByNames("Product", "Announcement")

// Register a SEO by model
type Product struct{
	Name  string
	Setting Setting

Remove models from SEO

// Remove by struct
// Remove by name
collection.RemoveSEO("Not Found")


Change the default global SEO name

collection.SetGlobalName("My Global SEO")

Change the default context db key

collection.SetDBContextKey("My DB")

Change the default SEO name

collection.RegisterSEO(&Product{}).SetName("My Product")

Register customized variables

	RegisterContextVariables("og:image", func(obj interface{}, _ *Setting, _ *http.Request) string {
		// this will render "og:image" with the value of the object in the current request
		return obj.image.url
	RegisterContextVariables("Name", func(obj interface{}, _ *Setting, _ *http.Request) string {
		return obj.Name

Register setting variable

This variable will be saved in the database and available as a global variable while editing SEO settings.

collection.RegisterSEO(&Product{}).RegisterSettingVaribles(struct{ProductTag string}{})

Render SEO html data

// Render Global SEO

// Render SEO by name
collection.Render("product", request)

// Render SEO by model
collection.Render(Product{}, request)


You can customize your SEO settings by implementing the interface and adding functions such as l10n and publish.

Suppose MySEOSetting implemented the above interface

type MySEOSetting struct{
		// publish
		// l10n

Use SetSettingModel function to set it




Collection manages all the registered models and hold global seo settings.

SEO provides system-level default page matadata.

You can use seo setting at the model level, but you need to register the model to the system SEO