modgen

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: ISC Imports: 5 Imported by: 0

README

modgen

Go Reference

Static generator for Go module import URLs.

Overview

modgen generates webpages to serve an Go module import URLs (also known as Vanity URLs). Unlike similar projects (e.g. govanityurls), modgen was designed to be static. This makes it possible to use static web hosting providers — like Github Pages, for example.

We are actually using Github Pages to host our own Go module import URLs, you can check the Github Actions workflow we use here!

For more informations on Go module imports, please refer to the official documentation.

Installation

go install essaim.dev/modgen/cmd/modgen@latest

Usage

Usage of modgen:
  -config string
        path of the configuration file (default "modgen.yaml")
  -index-tmpl string
        path of an optional custom index template
  -module-tmpl string
        path of an optional custom module template
  -target string
        path where the site should be generated (default "gen/")
Config file example
host: essaim.dev

modules:
  - path: /modgen
    vcs: git
    repo-url: https://github.com/essaim-dev/modgen

Note: All fields are mandatory.

Index template example
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>{{.Host}}</title>
</head>
<body>
	<h1>{{.Host}}</h1>
	<ul>
		{{range .Modules}}<li><a href="{{.Path}}">{{$.Host}}{{.Path}}</a></li>{{end}}
	</ul>
</body>
</html>
Module template example
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta name="go-import" content="{{.Path}} {{.VCS}} {{.RepoURL}}">
	<meta http-equiv="refresh" content="1; url=https://pkg.go.dev/{{.Path}}">
</head>
<body>
	<h1>{{.Path}}</h1>
	<p><a href="https://pkg.go.dev/{{.Path}}">See the package on pkg.go.dev</a>.</p>
</body>
</html>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host    string         `yaml:"host"`
	Modules []ModuleConfig `yaml:"modules"`
}

Config defines the format of a modgen configuration file.

func LoadConfig

func LoadConfig(path string) (Config, error)

LoadConfig tries to load and parse a modgen configuration file at the given path.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator contains the context required to generate a Go module import URL static site.

func NewGenerator

func NewGenerator(config Config) *Generator

func (*Generator) Generate

func (g *Generator) Generate(target string) error

func (*Generator) WithIndexTemplate

func (g *Generator) WithIndexTemplate(path string) error

func (*Generator) WithModuleTemplate

func (g *Generator) WithModuleTemplate(path string) error

type ModuleConfig

type ModuleConfig struct {
	Path    string `yaml:"path"`
	VCS     string `yaml:"vcs"`
	RepoURL string `yaml:"repo-url"`
}

Config defines an individual module from a configuration file.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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