pages

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorNotMatches 确认这不是 Gitea Pages 相关的域名
	ErrorNotMatches = errors.New("not matching")
	ErrorNotFound   = errors.New("not found")
	ErrorInternal   = errors.New("internal error")
)

Functions

This section is empty.

Types

type AutoRedirect

type AutoRedirect struct {
	Enabled bool
	Scheme  string
	Code    int
}

type ByteBuf

type ByteBuf struct {
	*bytes.Buffer
}

func NewByteBuf

func NewByteBuf(byte []byte) *ByteBuf

func (ByteBuf) Close

func (b ByteBuf) Close() error

type CustomDomains

type CustomDomains struct {
	/// 映射关系
	Alias *cmap.ConcurrentMap[string, PageDomain] `json:"alias,omitempty"`
	/// 反向链接
	Reverse *cmap.ConcurrentMap[string, string] `json:"reverse,omitempty"`
	/// 写锁
	Mutex sync.Mutex `json:"-"`
	/// 文件落盘
	Local string `json:"-"`
	// 是否全局共享
	Share bool `json:"-"`
}

func NewCustomDomains

func NewCustomDomains(local string, share bool) (*CustomDomains, error)

func (*CustomDomains) Get

func (d *CustomDomains) Get(host string) (PageDomain, bool)

type DomainCache

type DomainCache struct {
	*cache.Cache
	// contains filtered or unexported fields
}

func NewDomainCache

func NewDomainCache(ttl time.Duration, refreshTtl time.Duration) DomainCache

func (*DomainCache) Close

func (c *DomainCache) Close() error

func (*DomainCache) FetchRepo

func (c *DomainCache) FetchRepo(client *GiteaConfig, domain *PageDomain) (*DomainConfig, bool, error)

FetchRepo 拉取 Repo 信息

func (*DomainCache) Lock

func (c *DomainCache) Lock(any *PageDomain) func()

func (*DomainCache) LockAny

func (c *DomainCache) LockAny(any string) func()

type DomainConfig

type DomainConfig struct {
	FetchTime int64 //上次刷新时间

	PageDomain PageDomain
	Exists     bool         // 当前项目是否为 Pages
	FileCache  *cache.Cache // 文件缓存

	CNAME    []string        // 重定向地址
	SHA      string          // 缓存 SHA
	DATE     time.Time       // 文件提交时间
	BasePath string          // 根目录
	Topics   map[string]bool // 存储库标记

	Index    string //默认页面
	NotFound string //不存在页面
}

func (*DomainConfig) Close

func (receiver *DomainConfig) Close() error

func (*DomainConfig) Copy

func (receiver *DomainConfig) Copy(
	client *GiteaConfig,
	path string,
	writer http.ResponseWriter,
	_ *http.Request,
) (bool, error)

func (*DomainConfig) IsRoutePage

func (receiver *DomainConfig) IsRoutePage() bool

type ErrorMetadata

type ErrorMetadata struct {
	StatusCode int
	Request    *http.Request
	Error      string
}

type ErrorPages

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

func NewErrorPages

func NewErrorPages(pagesTmpl map[string]string) (*ErrorPages, error)

type FakeResponse

type FakeResponse struct {
	*http.Response
}

func NewFakeResponse

func NewFakeResponse() *FakeResponse

func (*FakeResponse) CacheMode

func (r *FakeResponse) CacheMode(mode string)

func (*FakeResponse) CacheModeHit

func (r *FakeResponse) CacheModeHit()

func (*FakeResponse) CacheModeIgnore

func (r *FakeResponse) CacheModeIgnore()

func (*FakeResponse) CacheModeMiss

func (r *FakeResponse) CacheModeMiss()

func (*FakeResponse) ContentType

func (r *FakeResponse) ContentType(types string)

func (*FakeResponse) ContentTypeExt

func (r *FakeResponse) ContentTypeExt(path string)

func (*FakeResponse) ETag

func (r *FakeResponse) ETag(tag string)

func (*FakeResponse) Length

func (r *FakeResponse) Length(len int)

func (*FakeResponse) SetHeader

func (r *FakeResponse) SetHeader(key string, value string)

type GiteaConfig

type GiteaConfig struct {
	Server        string            `json:"server"`
	Token         string            `json:"token"`
	Client        *gitea.Client     `json:"-"`
	Logger        *zap.Logger       `json:"-"`
	CustomHeaders map[string]string `json:"custom_headers"`
	CacheMaxSize  int               `json:"max_cache_size"`
}

func (*GiteaConfig) FileExists

func (c *GiteaConfig) FileExists(domain *PageDomain, path string) (bool, error)

func (*GiteaConfig) OpenFileContext

func (c *GiteaConfig) OpenFileContext(domain *PageDomain, path string) (*http.Response, error)

func (*GiteaConfig) ReadRepoFile

func (c *GiteaConfig) ReadRepoFile(domain *PageDomain, path string) ([]byte, error)

func (*GiteaConfig) ReadStringRepoFile

func (c *GiteaConfig) ReadStringRepoFile(domain *PageDomain, path string) (string, error)

type MiddlewareConfig

type MiddlewareConfig struct {
	Server        string            `json:"server"`
	Token         string            `json:"token"`
	Domain        string            `json:"domain"`
	Alias         string            `json:"alias"`
	CacheRefresh  time.Duration     `json:"cache_refresh"`
	CacheTimeout  time.Duration     `json:"cache_timeout"`
	ErrorPages    map[string]string `json:"errors"`
	CustomHeaders map[string]string `json:"custom_headers"`
	AutoRedirect  *AutoRedirect     `json:"redirect"`
	SharedAlias   bool              `json:"shared_alias"`
	CacheMaxSize  int               `json:"cache_max_size"`
}

type OwnerCache

type OwnerCache struct {
	*cache.Cache
	// contains filtered or unexported fields
}

func NewOwnerCache

func NewOwnerCache(ttl time.Duration, cacheTtl time.Duration) OwnerCache

func (*OwnerCache) GetOwnerConfig

func (c *OwnerCache) GetOwnerConfig(giteaConfig *GiteaConfig, owner string) (*OwnerConfig, error)

func (*OwnerCache) Lock

func (c *OwnerCache) Lock(any string) func()

type OwnerConfig

type OwnerConfig struct {
	FetchTime  int64           `json:"fetch_time,omitempty"`
	Repos      map[string]bool `json:"repos,omitempty"`
	LowerRepos map[string]bool `json:"lower_repos,omitempty"`
}

func NewOwnerConfig

func NewOwnerConfig() *OwnerConfig

func (*OwnerConfig) Exists

func (c *OwnerConfig) Exists(repo string) bool

type PageClient

type PageClient struct {
	BaseDomain   string
	GiteaConfig  *GiteaConfig
	DomainAlias  *CustomDomains
	ErrorPages   *ErrorPages
	AutoRedirect *AutoRedirect
	OwnerCache   *OwnerCache
	DomainCache  *DomainCache
	// contains filtered or unexported fields
}

func NewPageClient

func NewPageClient(
	config *MiddlewareConfig,
	logger *zap.Logger,
) (*PageClient, error)

func (*PageClient) Close

func (p *PageClient) Close() error

func (*PageClient) Route

func (p *PageClient) Route(writer http.ResponseWriter, request *http.Request) error

func (*PageClient) RouteExists

func (p *PageClient) RouteExists(writer http.ResponseWriter, request *http.Request) error

func (*PageClient) Validate

func (p *PageClient) Validate() error

type PageDomain

type PageDomain struct {
	Owner  string `json:"owner"`
	Repo   string `json:"repo"`
	Branch string `json:"branch"`
}

func NewPageDomain

func NewPageDomain(owner string, repo string, branch string) *PageDomain

func (*PageDomain) Key

func (p *PageDomain) Key() string

Jump to

Keyboard shortcuts

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