gwi

package module
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: GPL-2.0 Imports: 21 Imported by: 1

README

This project delivers various functions to be used in your server, with that you can customize all pages and paths.

Usage

The simplest way of using this project is the following example:

package main

import (
	"net/http"

	"blmayer.dev/gwi"
)

func main() {
	// init user vault
	v, err := NewFileVault("users.json", "--salt--")
	// handle error
	
	// gwi config struct
	c := gwi.Config{
		Root: "path/to/git/folder",
		PagesRoot: "path/to/html-templates",
		...
	}

	g, _ := gwi.NewFromConfig(c, v)
	// handle error

	err := http.ListenAndServe(":8080", g.Handle())
	// handle err
}

This gives you the main handlers, i.e. routes like /{user}/{repo}/{ref}/{op}/{args}, args is an optional parameter.

This makes gwi interact with the repository repo that belongs to user, so it must be found under the folder config.Root/user/repo in the server.

op makes gwi look for a template named op.html in gwi.PagesRoot folder, and execute it.

Functions

This package provides functions that you can call in your templates, letting you query the data you want in an efficient way. Currently gwi exports the following functions:

  • users: func() []string
  • repos: func(user string) []string
  • branches: func(ref plumbing.Hash) []*plumbing.Reference
  • tags: func() []*plumbing.Reference
  • commits: func(ref plumbing.Hash) []*object.Commit
  • commit: func(ref plumbing.Hash) *object.Commit
  • tree: func(ref plumbing.Hash) []File
  • file: func(ref plumbing.Hash, name string) string
  • markdown: func(in string) template.HTML

Their names indicate what info they return, to see examples browse the template folder.

Variables

In addition to the functions above, gwi injects the following struct as data in all templates:

type RepoInfo struct {
	User     string
	Repo     string
	Ref      plumbing.Hash
	RefName  string
	Args     string
}

All fields are automatically populated, in special, args comes from the route part.

Examples

Users

To get a list of your users is simple:

<ul>
	{{range users}}
	<li>{{.}}</li>
	{{end}}
</ul>
File tree

To get the file tree for the current reference:

<table>
    <tr>
        <th>Mode</th>
        <th>Size</th>
        <th>Name</th>
    </tr>
    {{range tree .Ref}}
    <tr>
        <td>{{.Mode}}</td>
        <td>{{.Size}}</td>
	<td>{{.Name}}</td>
    </tr>
    {{end}}
</table>

Will print a nice list of your project files.

Commits

Using the functions commits and commit you're able to see a list of commits and check details of each one:

<table>
    <tr>
        <th>Time</th>
        <th>Author</th>
        <th>Message</th>
    </tr>
    {{range commits .Ref}}
    <tr>
        <td>{{.Author.When.String}}</td>
        <td>{{.Author.Name}}</td>
	<td>{{.Message}}</td>
    </tr>
    {{end}}
</table>

To get the list, and the following show a commit's details:

{{with commit .Ref}}

<p><b>Commited at:</b> {{.Committer.When.String}}</p>
<p><b>Author:</b> {{.Committer.Name}} ({{.Committer.Email}})</p>
<p><b>Message:</b></p>
<p>{{.Message}}</p>
{{end}}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Domain      string
	MailAddress string
	PagesRoot   string
	Root        string
	CGIRoot     string
	CGIPrefix   string
	LogLevel    logger.Level
	// contains filtered or unexported fields
}

type Email added in v0.9.0

type Email struct {
	From        string
	To          string
	Cc          string
	Date        time.Time
	Subject     string
	Body        string
	Attachments map[string][]byte
}

type File

type File struct {
	*object.File
	Size int64
}

type FileMailer added in v0.9.0

type FileMailer struct {
	Root string
	*smtp.Server
}

type FileVault

type FileVault struct {
	Users map[string]User
	// contains filtered or unexported fields
}

func NewFileVault

func NewFileVault(path, salt string) (FileVault, error)

func (FileVault) GetUser added in v0.10.0

func (f FileVault) GetUser(login string) User

func (FileVault) Mix

func (f FileVault) Mix(data string) string

func (FileVault) Validate

func (f FileVault) Validate(login, pass string) bool

type Gwi

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

func NewFromConfig

func NewFromConfig(config Config, vault Vault) (Gwi, error)

func (Gwi) AnonymousLogin added in v0.10.0

func (g Gwi) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, error)

func (*Gwi) CloseThread added in v0.10.0

func (g *Gwi) CloseThread(threadPath string) error

Close moves a thread to the closed folder

func (Gwi) Commands added in v0.10.0

func (g Gwi) Commands() map[string]func(content, thread string) bool

func (*Gwi) GitCGIHandler

func (g *Gwi) GitCGIHandler(w http.ResponseWriter, r *http.Request)

func (*Gwi) Handle

func (g *Gwi) Handle() http.Handler

func (*Gwi) ListHandler added in v0.5.0

func (g *Gwi) ListHandler(w http.ResponseWriter, r *http.Request)

func (Gwi) Login added in v0.10.0

func (g Gwi) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error)

func (*Gwi) Mail added in v0.10.0

func (g *Gwi) Mail(file string) (Email, error)

func (*Gwi) Mails added in v0.10.0

func (g *Gwi) Mails(folder string) ([]Email, error)

func (*Gwi) MainHandler added in v0.5.0

func (g *Gwi) MainHandler(w http.ResponseWriter, r *http.Request)

func (*Gwi) NewMailServer added in v0.10.0

func (g *Gwi) NewMailServer() FileMailer

func (Gwi) NewSession added in v0.10.0

func (g Gwi) NewSession(_ *smtp.Conn) (smtp.Session, error)

func (*Gwi) Private

func (g *Gwi) Private(h http.HandlerFunc) http.HandlerFunc

func (*Gwi) Threads added in v0.10.0

func (g *Gwi) Threads(folder string) ([]Thread, error)

type Info added in v0.5.0

type Info struct {
	User    string
	Repo    string
	Ref     plumbing.Hash
	RefName string
	Args    string
}

type Mailer added in v0.9.0

type Mailer interface {
	Threads(folder string) ([]Thread, error)
	Mails(folder string) ([]Email, error)
	Mail(path string) (Email, error)
	Close(thread string) error
	Commands() map[string]func(content, thread string) bool
}

type Session added in v0.8.0

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

A Session is returned after EHLO.

func (Session) AuthPlain added in v0.8.0

func (s Session) AuthPlain(username, password string) error

func (Session) Data added in v0.8.0

func (s Session) Data(r io.Reader) error

func (Session) Logout added in v0.8.0

func (s Session) Logout() error

func (Session) Mail added in v0.8.0

func (s Session) Mail(from string, opts smtp.MailOptions) error

func (Session) Rcpt added in v0.8.0

func (s Session) Rcpt(to string) error

func (Session) Reset added in v0.8.0

func (s Session) Reset()

type Thread added in v0.8.0

type Thread struct {
	Title   string
	Creator string
	LastMod time.Time
	Lenght  int
	Status  ThreadStatus
}

type ThreadStatus added in v0.8.0

type ThreadStatus string

type User

type User struct {
	Email string
	Login string
	Pass  string
}

type Vault

type Vault interface {
	GetUser(login string) any
	Validate(login, pass string) bool
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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