Documentation ¶
Overview ¶
This package implements common federated wiki types
Index ¶
- Constants
- Variables
- func AddCSPHeader(w http.ResponseWriter) string
- func AddCommonHeaders(w http.ResponseWriter)
- func ExtractSynopsis(page *Page) string
- func ExtractTags(page *Page) []string
- func NewID() string
- func SlugToTitle(slug Slug) string
- func SlugifyTags(tags []string) []string
- func SortGroupsByPriority(user User, groups []Group)
- func SortPageEntries(xs []PageEntry, fn func(a, b *PageEntry) bool)
- func SortPageEntriesByDate(xs []PageEntry)
- func SortPageEntriesByRank(xs []PageEntry, ranking []Slug)
- func SortPageEntriesBySlug(xs []PageEntry)
- func SortTagEntriesByName(xs []TagEntry)
- func ValidateSlug(slug Slug) error
- func WriteResult(w http.ResponseWriter, err error)
- type Access
- type Action
- type Auth
- type Context
- type Database
- type Group
- type Groups
- type GuestLogin
- type Index
- type Item
- type Member
- type Module
- type Page
- type PageEntry
- type Pages
- type Params
- type Rights
- type Server
- func (server *Server) AddModule(module Module)
- func (server *Server) AdminContext(w http.ResponseWriter, r *http.Request) (Context, bool)
- func (server *Server) GroupContext(w http.ResponseWriter, r *http.Request, min Rights) (Context, Slug, bool)
- func (server *Server) IndexContext(w http.ResponseWriter, r *http.Request) (Context, Index, bool)
- func (server *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (server *Server) UserContext(w http.ResponseWriter, r *http.Request) (Context, bool)
- type Slug
- type Story
- func (s *Story) Append(item ...Item)
- func (s Story) IndexOf(id string) (index int, ok bool)
- func (s *Story) InsertAfter(id string, item Item) error
- func (ps *Story) Move(id string, afterId string) error
- func (s *Story) Prepend(item Item)
- func (s *Story) RemoveByID(id string) (item Item, err error)
- func (s Story) SetByID(id string, item Item) error
- type TagEntry
- type User
- type Users
Constants ¶
View Source
const ( Blocked Rights = "blocked" Reader = "reader" Editor = "editor" Moderator = "moderator" )
View Source
const DefaultBucketName = "rt-knowledge-base-dev"
AWS S3 related
View Source
const DefaultRegion = "us-east-1"
Variables ¶
View Source
var ( // S3 requests related errors ErrUnableToDelete = errors.New("Unable to delete given object.") ErrUnableToCreateS3Session = errors.New("Unable to create S3 session.") ErrDoesNotExist = errors.New("404 Not Found") ErrBadRequest = errors.New("Bad request, likely due to invalid input.") )
View Source
var ( ErrUserExists = errors.New("User already exists.") ErrUserNotExist = errors.New("User does not exist.") ErrGroupExists = errors.New("Group already exists.") ErrGroupNotExist = errors.New("Group does not exist.") ErrPageExists = errors.New("Page already exists.") ErrPageNotExist = errors.New("Page does not exist.") ErrConcurrentEdit = errors.New("Concurrent modification of page.") ErrInvalidSlug = errors.New("Invalid slug.") )
View Source
var (
ErrUnknownAction = errors.New("unknown action")
)
Functions ¶
func AddCSPHeader ¶
func AddCSPHeader(w http.ResponseWriter) string
func AddCommonHeaders ¶
func AddCommonHeaders(w http.ResponseWriter)
func ExtractSynopsis ¶
func ExtractTags ¶
func SlugToTitle ¶
func SlugifyTags ¶
func SortGroupsByPriority ¶
func SortPageEntries ¶
func SortPageEntriesByDate ¶
func SortPageEntriesByDate(xs []PageEntry)
func SortPageEntriesByRank ¶
func SortPageEntriesBySlug ¶
func SortPageEntriesBySlug(xs []PageEntry)
func SortTagEntriesByName ¶
func SortTagEntriesByName(xs []TagEntry)
func ValidateSlug ¶
ValidateSlug verifies whether a `slug` is valid
func WriteResult ¶
func WriteResult(w http.ResponseWriter, err error)
Types ¶
type Access ¶
type Access interface { VerifyUser(user User) error IsAdmin(user Slug) bool SetAdmin(user Slug, isAdmin bool) error Rights(group, user Slug) Rights // member is either a User or a Group AddUser(group, user Slug) error RemoveUser(group, user Slug) error CommunityAdd(group, member Slug, rights Rights) error CommunityRemove(group, member Slug) error List(group Slug) ([]Member, error) }
type Action ¶
type Action map[string]interface{}
Action represents a operation that can be applied to a fedwiki.Page
func (Action) Str ¶
Str returns string value by the key if that key doesn't exist, it will return an empty string
type Group ¶
func (*Group) IsCommunity ¶
type GuestLogin ¶
type Index ¶
type Index interface { List() ([]PageEntry, error) Search(text string) ([]PageEntry, error) SearchFilter(text, exclude, include string) ([]PageEntry, error) Tags() ([]TagEntry, error) ByTag(tag Slug) ([]PageEntry, error) ByTagFilter(tag []Slug, exclude, include string) ([]PageEntry, error) Groups(min Rights) ([]Group, error) ByGroup(groupID Slug) ([]PageEntry, error) ByTitle(title Slug) ([]PageEntry, error) RecentChanges(n int) ([]PageEntry, error) RecentChangesByGroup(n int, groupID Slug) ([]PageEntry, error) }
type Item ¶
type Item map[string]interface{}
Item represents a federated wiki Story item
func ItemsFromEntries ¶
type Page ¶
type Page struct { Version int `json:"version"` Slug Slug `json:"slug"` Title string `json:"title"` Synopsis string `json:"synopsis,omitempty"` Modified time.Time `json:"modified,omitempty"` Story Story `json:"story,omitempty"` }
Page represents a federated wiki page
func (*Page) CanonicalizeIDs ¶
func (p *Page) CanonicalizeIDs()
func (*Page) WriteResponse ¶
func (p *Page) WriteResponse(w http.ResponseWriter) error
type PageEntry ¶
type PageEntry struct { Slug Slug `json:"slug"` Title string `json:"title"` Synopsis string `json:"synopsis"` Tags []string `json:"tags"` Modified time.Time `json:"modified"` }
func PageEntryFrom ¶
type Pages ¶
type Pages interface { Create(page *Page) error Load(id Slug) (*Page, error) LoadRaw(id Slug) ([]byte, error) LoadRawVersion(id Slug, version int) ([]byte, error) Overwrite(id Slug, version int, page *Page) error Edit(id Slug, version int, action Action) error Delete(id Slug, version int) error BatchReplace(pages map[Slug]*Page, complete func(string, Slug)) error BatchReplaceDelta(pages map[Slug]*Page, complete func(string, Slug)) error List() ([]PageEntry, error) History(id Slug) ([]PageEntry, error) }
type Server ¶
func (*Server) AdminContext ¶
func (*Server) GroupContext ¶
func (*Server) IndexContext ¶
func (*Server) UserContext ¶
type Slug ¶
type Slug string
Slug is a string where Slugify(string(slug)) == slug
func Slugify ¶
Slugify converts text to a slug
- numbers, '/', '=' are emitted
- letters will be lowercased (if possible)
- '-', ',', '.', ' ', '_' will be converted to '-'
- repeated '/' and '=' are removed
- other symbols or punctuations will be converted to html entity reference name (if there exists such reference name)
- everything else will be converted to '-'
Example:
"&Hello_世界/+!" ==> "amp-hello-世界/plus-excl" "Hello World // Test" ==> "hello-world/test"
func TokenizeLink ¶
func TokenizeLink3 ¶
type Story ¶
type Story []Item
Story is the viewable content of the page
func StoryFromEntries ¶
func (Story) IndexOf ¶
IndexOf returns the index of an item with `id` ok = false, if that item doesn't exist
func (*Story) InsertAfter ¶
InsertAfter adds the `item` after the item with `id`
func (*Story) RemoveByID ¶
Removes item with `id`
Source Files ¶
Click to show internal directories.
Click to hide internal directories.