redirect

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package redirect contains logic for resovling ambiquios redirects and generic Git Web UI URLs. To define a new redirect rule, create a new struct which implements interface redirectRule. Then, add it to NewRules.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoMatch indicates no commit can be found.
	ErrNoMatch = errors.New("no match found")
)

Functions

This section is empty.

Types

type GitRedirect

type GitRedirect interface {
	// Commit returns URL to a specific commit.
	Commit(models.Commit, string) (string, error)
	// Diff returns URL for viewing difference between two commits.
	Diff(models.Commit, models.Commit) (string, error)
}

GitRedirect is interface for generating URLs.

func NewCodesearchRedirect

func NewCodesearchRedirect() GitRedirect

NewCodesearchRedirect returns struct that implements GitRedirect interface. All methods return URLs to source.chromium.org instance.

func NewGitilesRedirect

func NewGitilesRedirect() GitRedirect

NewGitilesRedirect returns struct that implements GitRedirect interface. All methods return URLs to Gitiles instance.

type Rules

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

Rules holds all available redirect rules. The order of rules matter, so generic / catch-all rules should be last.

func NewRules

func NewRules(redirect GitRedirect) *Rules

NewRules creates new instance of RedirectRules with hardcoded rules. New rules should be added here.

func (*Rules) FindRedirectURL

func (r *Rules) FindRedirectURL(ctx context.Context, url string) (string, *models.Commit, error)

FindRedirectURL returns destination URL on the first matching redirectRule. If nothing is found, errNoMatch is returned.

Jump to

Keyboard shortcuts

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