docgen

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 18 Imported by: 0

README

docgen-yes

This Git repo is a maintained fork of docgen. Here all PRs are welcome. The upstream docgen is more conservative.

The libraries docgen and docgen-yes both auto-generates routing documentation for a chi Router from your app source.

Differences

The upstream docgen is very stable, while docgen-yes includes experimental new features.

Generator docgen docgen-yes
JSON ✔ Stable ✔ Minor enahcements
Markdown ✔ Stable ✔ Minor enahcements
HTML ✔ Experimental

Example

Example use of the JSON and Markdown generators.

Example Screenshot (screenshot made with Carbon and retouched with GIMP)

import

Upstream docgen
import (
  "net/http"

  "github.com/go-chi/chi/v5"
  "github.com/go-chi/docgen"
)
To use this fork
import (
  "net/http"

  "github.com/go-chi/chi/v5"
  "github.com/teal-finance/docgen-yes" // note the change
)

Experimental HTML generator

  • Templates built, passing tests
  • HTML Generator is being built, not yet functional (3/18/2018)
    • 85% complete
    • 15% remaining: String building for routes, middleware, handlers & related tests
  • Configuration obj
  • New code inspired from markdown.go
  • See markup.go and markupTemplates.go
  • Designed & implemented by forrest321

Test

Many tests are currently empty: they have just been generated by cweill/gotests.

go test -race -vet all ./...

Documentation

Overview

Package docgen generates the Chi routes documentation in JSON or Markdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseTemplate added in v1.2.2

func BaseTemplate() string

BaseTemplate is a basic html page with placeholders for: {title}, {css}, {intro}, and {routes}.

func BassCSS added in v1.2.2

func BassCSS() string

BassCSS is a zero config drop in css kit.

func Div added in v1.2.2

func Div(text string) string

Div wraps the string with <div> tags.

func FaviconIcoData added in v1.2.2

func FaviconIcoData() string

FaviconIcoData contains image data converted with https://www.motobit.com/util/base64/image-to-base64/

func Head(level int, text string) string

Head creates a header for a given level eg H1, H2, H3...

func JSONRoutesBytes added in v1.4.0

func JSONRoutesBytes(r chi.Routes) []byte

func JSONRoutesDoc

func JSONRoutesDoc(r chi.Routes) string

func ListItem added in v1.2.2

func ListItem(text string) string

ListItem is an item for a list.

func MarkdownRoutesDoc

func MarkdownRoutesDoc(r chi.Router, opts MarkdownOpts) string

func MarkupRoutesDoc added in v1.2.2

func MarkupRoutesDoc(r chi.Router, opts MarkupOpts) string

MarkupRoutesDoc builds a document based on routes in a given router with given option set.

func MilligramMinCSS added in v1.2.2

func MilligramMinCSS() string

MilligramMinCSS is a tiny CSS kit, minimized and stringified here.

func OrderedList added in v1.2.2

func OrderedList(listItems string) string

OrderedList is a numbered list.

func P added in v1.2.2

func P(text string) string

P wraps the string with <p> tags.

func PrintRoutes

func PrintRoutes(r chi.Routes)

func UnorderedList added in v1.2.2

func UnorderedList(listItems string) string

UnorderedList is a list using bullet points instead of numbers.

Types

type Doc

type Doc struct {
	Router DocRouter `json:"router"`
}

func BuildDoc

func BuildDoc(r chi.Routes) (Doc, error)

type DocHandler

type DocHandler struct {
	Middlewares []DocMiddleware `json:"middlewares"`
	Method      string          `json:"method"`
	FuncInfo
}

type DocHandlers

type DocHandlers map[string]DocHandler // Method : DocHandler

type DocMiddleware

type DocMiddleware struct {
	FuncInfo
}

type DocRoute

type DocRoute struct {
	Pattern  string      `json:"-"`
	Handlers DocHandlers `json:"handlers,omitempty"`
	Router   *DocRouter  `json:"router,omitempty"`
}

type DocRouter

type DocRouter struct {
	Middlewares []DocMiddleware `json:"middlewares"`
	Routes      DocRoutes       `json:"routes"`
}

func BuildDocRouter added in v1.3.0

func BuildDocRouter(r chi.Routes) DocRouter

type DocRoutes

type DocRoutes map[string]DocRoute // Pattern : DocRoute

type FuncInfo

type FuncInfo struct {
	Pkg          string    `json:"pkg"`
	Func         string    `json:"func"`
	Comment      string    `json:"comment"`
	File         string    `json:"file,omitempty"`
	ASTFile      *ast.File `json:"ast_file,omitempty"`
	Line         int       `json:"line,omitempty"`
	Anonymous    bool      `json:"anonymous,omitempty"`
	Unresolvable bool      `json:"unresolvable,omitempty"`
}

FuncInfo describes a function's metadata.

func GetFuncInfo added in v1.0.1

func GetFuncInfo(i any) FuncInfo

GetFuncInfo returns a FuncInfo object for a given interface.

type MarkdownDoc

type MarkdownDoc struct {
	Opts   MarkdownOpts
	Router chi.Router
	Doc    Doc
	Routes map[string]DocRouter // Pattern : DocRouter
	// contains filtered or unexported fields
}

func (*MarkdownDoc) Generate

func (md *MarkdownDoc) Generate() error

func (*MarkdownDoc) String

func (md *MarkdownDoc) String() string

func (*MarkdownDoc) WriteIntro

func (md *MarkdownDoc) WriteIntro()

func (*MarkdownDoc) WriteRoutes

func (md *MarkdownDoc) WriteRoutes()

type MarkdownOpts

type MarkdownOpts struct {
	// ProjectPath is the base Go import path of the project
	ProjectPath string

	// Intro text included at the top of the generated markdown file.
	Intro string

	// ForceRelativeLinks to be relative even if they're not on github
	ForceRelativeLinks bool

	// URLMap allows specifying a map of package import paths to their link sources
	// Used for mapping vendored dependencies to their upstream sources
	// For example:
	// map[string]string{"github.com/my/package/vendor/go-chi/chi/": "https://github.com/go-chi/chi/blob/master/"}
	URLMap map[string]string
}

type MarkupDoc added in v1.2.2

type MarkupDoc struct {
	Opts          MarkupOpts
	Router        chi.Router
	Doc           Doc
	Routes        map[string]DocRouter // Pattern : DocRouter
	FormattedHTML string
	RouteHTML     string
}

MarkupDoc describes a document to be generated.

func (*MarkupDoc) String added in v1.2.2

func (mu *MarkupDoc) String() string

String pretty prints the document.

type MarkupOpts added in v1.2.2

type MarkupOpts struct {
	// ProjectPath is the base Go import path of the project
	ProjectPath string

	// Intro text included at the top of the generated markdown file.
	Intro string

	// RouteText contains HTML generated from Route metadata
	RouteText string

	// ForceRelativeLinks to be relative even if they're not on github
	ForceRelativeLinks bool

	// URLMap allows specifying a map of package import paths to their link sources
	// Used for mapping vendored dependencies to their upstream sources
	// For example:
	// map[string]string{"github.com/my/package/vendor/go-chi/chi/": "https://github.com/go-chi/chi/blob/master/"}
	URLMap map[string]string
}

MarkupOpts describes the options for a MarkupDoc.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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