aurora

package module
v0.0.0-...-8f0ec35 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2015 License: MIT Imports: 26 Imported by: 1

README

aurora Build StatusCoverage Status GoDoc

What is aurora?

Aurora is a lightweight social network application written in Go programming language, and using bolt database as its main storage source.

This is not for production use, I started this project as a way to learn more about the Go programming language, and also to experiment with testing web services in Go.

Guide

  1. Getting started
    • Overview
    • Installation
Alternative way to build

I was digging in the go standard library, and thought I should experiment on the text/template. I extended it and made a toy yet working build tool(a.k.a template based build tool). The source code is found here zanzibar.

You can build aurora using zanzibar tool. Install it first.

go get github.com/gernest/zanzibar

clone aurora

git clone https://github.com/gernest/aurora

cd into aurora and run zanzibar

cd aurora&&zanzibar

you should find your build in builds directory.

Roadmap

Features

  • chat
  • profile management
  • photo upload
  • ??? any ideas?

Scrrenshots


screenshot1

screenshot2

Contributing

This is a playground, all kinds of contibutions are welcome. Since it is for learning and experimenting, feel free to think of new ideas.

The important thing is to test, whatever you add make sure it has tests. Also be clear on what exactly ypur PR does.

License

This project is under the MIT License. See the LICENSE file for the full license text.

Documentation

Overview

Package aurora is a minimalistic social network library.

Index

Constants

This section is empty.

Variables

View Source
var (
	// MsgRequired is the error message for required validation.
	MsgRequired = "hili eneo halitakiwi kuachwa wazi"

	// MsgName is the error message displayed for a name validation
	MsgName = "hili eneo linatakiwa liwe mchanganyiko wa herufi na namba"

	//MsgEmail is the error message displayed for email validation
	MsgEmail = "email sio sahihi. mfano gernest@aurora.com"

	// MsgMinLength is the error message for a minimum length validation
	MsgMinLength = "namba ya siri inatakiwa kuanzia herufi 6 na kuendelea"

	// MsgEqual is the error message for equality validation
	MsgEqual = "%s inatakiwa iwe sawa na %s"

	// MsgMinAge the minimum age linit
	MsgMinAge = "umri unatakiwa uwe zaidi ya miaka %d"
)
View Source
var ISO3166List = []ISO3166Entry{}/* 249 elements not displayed */

ISO3166List based on https://www.iso.org/obp/ui/#search/code/ Code Type "Officially Assigned Codes"

View Source
var SupportedCountries = []ISO3166Entry{
	{"Tanzania, United Republic of", "Tanzanie, République-Unie de", "TZ", "TZA", "834"},
}

SupportedCountries these are the coutries supported by aurora

Functions

func ComposeLoginForm

func ComposeLoginForm() gforms.ModelForm

ComposeLoginForm builds a login form for validation( with gforms)

func ComposeProfileForm

func ComposeProfileForm() gforms.ModelForm

ComposeProfileForm builds a profile form for validation (using gform)

func ComposeRegisterForm

func ComposeRegisterForm() gforms.ModelForm

ComposeRegisterForm builds a registration form for validation(with gforms)

func CreateAccount

func CreateAccount(db nutz.Storage, a Account, bucket string) error

CreateAccount creates a new account, where id will be the value returned by invoking Email() method.

func CreateProfile

func CreateProfile(db nutz.Storage, p *Profile, bucket string, nest ...string) error

CreateProfile creates a new profile using Profile.ID as the jey

func GetAllUsers

func GetAllUsers(db nutz.Storage, bucket string, nest ...string) ([]string, error)

GetAllUsers returns a slice of all users.

func UpdateProfile

func UpdateProfile(db nutz.Storage, p *Profile, bucket string, nest ...string) error

UpdateProfile updates a given profile

Types

type Account

type Account interface {
	Email() string
	Password() string
}

Account is an interface for a user account

type BirthDateValidator

type BirthDateValidator struct {
	Limit   int
	Message string
	gforms.Validator
}

BirthDateValidator validates the birth date, handy to keep minors offsite

func (BirthDateValidator) Validate

Validate checks if the given field instance esceeds the Limit attribute

type CustomValidator

type CustomValidator struct {
	Vf      validateFunc
	Message string
	gforms.Validator
}

CustomValidator a custom validator for gforms

func IsName

func IsName() CustomValidator

IsName retruns a name validator

func (CustomValidator) Validate

Validate validates fields

type EqualValidator

type EqualValidator struct {
	gforms.Validator

	Message string
	// contains filtered or unexported fields
}

EqualValidator checks if the two fields are equal. The to attribute is the name of the field whose value must be equal to the current field

func (EqualValidator) Validate

Validate checks if the given field is egual to the field in the to attribute

type FileUpload

type FileUpload struct {
	Body *multipart.File
	Ext  string
}

FileUpload represents the uploaded file

func GetFileUpload

func GetFileUpload(r *http.Request, fieldName string) (*FileUpload, error)

GetFileUpload retrieves uploaded file from a request.This function, returns only the first file that matches, thus retrieving a single file only. the fieldName parameter is the name of the field which holds the file data.

func GetMultipleFileUpload

func GetMultipleFileUpload(r *http.Request, fieldName string) ([]*FileUpload, error)

GetMultipleFileUpload retrieves multiple files uploaded on a single request. The fieldName parameter is the form field containing the files

type Flash

type Flash struct {
	Data map[string]interface{}
}

Flash is a helper for storing and retrieving flash messages TODO : Move this to another file, it just don't look like it belongs here

func NewFlash

func NewFlash() *Flash

NewFlash creates a new flash

func (*Flash) Error

func (f *Flash) Error(msg string)

Error adds an error message

func (*Flash) Get

func (f *Flash) Get(s *sessions.Session) *Flash

Get retrieves any flash messages in the session

func (*Flash) Notice

func (f *Flash) Notice(msg string)

Notice adds a notice flash message

func (*Flash) Save

func (f *Flash) Save(s *sessions.Session)

Save saves the flsah to the given session

func (*Flash) Success

func (f *Flash) Success(msg string)

Success adds a success message

type ISO3166Entry

type ISO3166Entry struct {
	EnglishShortName string `json:"eglish_short_name"`
	FrenchShortName  string `json:"french_short_name"`
	Alpha2Code       string `json:"alpha2code"`
	Alpha3Code       string `json:"alpha3code"`
	Numeric          string `json:"numeric"`
}

ISO3166Entry stores country codes

type InfoMSG

type InfoMSG struct {
	Title  string `json:"title"`
	Body   string `json:"body"`
	Sender string `json:"sender"`
}

InfoMSG this is for sharing information across the messenger nodes

type MSG

type MSG struct {
	ID          string    `json:"id"`
	SenderID    string    `json:"sender_id"`
	RecipientID string    `json:"recepient_id"`
	Text        string    `json:"text"`
	SentAt      time.Time `json:"sent_at"`
	ReceivedAt  time.Time `json:"received_at"`
	Status      int       `json:"status"`
	SenderName  string    `json:"sender_name"`
}

MSG this is the base message exchanged between users

type Messenger

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

Messenger the messanger from the gods

func NewMessenger

func NewMessenger(rx *Remix) *Messenger

NewMessenger creates a new messenger

func (*Messenger) Handler

func (m *Messenger) Handler() func(http.ResponseWriter, *http.Request)

Handler handles websocket connections for messaging

type Photo

type Photo struct {
	ID string `json:"id"`

	// Type is the photo's file extension e.g jpeg or png
	Type string `json:"type"`

	//Size is the size of the photo.
	Size int `json:"size"`

	//UploadedBy is the ID of the user who uploaded the photo
	UploadedBy string `json:"uploaded_by"`

	UploadedAt time.Time `json:"uploaded_at"`

	// UpdatedAt is the time the photo was updated. I keep this filed so as
	// to provide, last modified time when serving the photo.
	UpdatedAt time.Time `json:"updated_at"`
}

Photo is the metadata of an uploaded image file

func SaveUploadFile

func SaveUploadFile(db nutz.Storage, file *FileUpload, p *Profile) (*Photo, error)

SaveUploadFile saves the uploaded photos to the profile database. In aurora, every user has his/her own personal database.

The db argument should be the user's database. The uploaded file is storesd in two versions meta, and data. The meta, is the metadata about the uploaded file, in our case a Photo object. The photo object is marshalled and stored in a metaBucket.

The data part is the actual encoded file, its stored in the dataBucket.

type Profile

type Profile struct {
	ID        string    `json:"id" gforms:"-"`
	FirstName string    `json:"first_name" gforms:"first_name"`
	LastName  string    `json:"last_name" gforms:"last_name"`
	Picture   *Photo    `json:"picture" gforms:"-"`
	Age       int       `json:"age" gforms:"age"`
	IsUpdate  bool      `json:"is_update" gforms:"-"`
	BirthDate time.Time `json:"birth_date" gforms:"birth_date"`
	Gender    int       `json:"gender" gforms:"gender"`
	Photos    []*Photo  `json:"photos" gforms:"-"`
	City      string    `json:"city" gforms:"city"`
	Country   string    `json:"country" gforms:"country"`
	Street    string    `json:"street" gforms:"street"`
	CreatedAt time.Time `json:"created_at" gforms:"-"`
	UpdatedAt time.Time `json:"update_at" gforms:"-"`
}

Profile contains additional information about the user

func GetProfile

func GetProfile(db nutz.Storage, bucket, id string, nest ...string) (*Profile, error)

GetProfile retrives a profile with a given id

func (*Profile) MyBirthDay

func (p *Profile) MyBirthDay() string

func (*Profile) Sex

func (p *Profile) Sex() string

type Remix

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

Remix all the fun is here

func NewRemix

func NewRemix(cfg *RemixConfig) *Remix

NewRemix iitialize a *Remix instance using the given cfg

func (*Remix) Home

func (rx *Remix) Home(w http.ResponseWriter, r *http.Request)

Home is where the homepage is

func (*Remix) Login

func (rx *Remix) Login(w http.ResponseWriter, r *http.Request)

Login creates new session for a user

func (*Remix) Logout

func (rx *Remix) Logout(w http.ResponseWriter, r *http.Request)

Logout deletes current session

func (*Remix) Profile

func (rx *Remix) Profile(w http.ResponseWriter, r *http.Request)

Profile viewing and updating profile

func (*Remix) Register

func (rx *Remix) Register(w http.ResponseWriter, r *http.Request)

Register creates a new user account

func (*Remix) Routes

func (rx *Remix) Routes() *mux.Router

Routes returs a mux of all registered routes

func (*Remix) ServeImages

func (rx *Remix) ServeImages(w http.ResponseWriter, r *http.Request)

ServeImages serves images uploaded by users

func (*Remix) Uploads

func (rx *Remix) Uploads(w http.ResponseWriter, r *http.Request)

Uploads uploads files

type RemixConfig

type RemixConfig struct {
	AppName        string `json:"name"`
	AppURL         string `json:"url"`
	CdnMode        bool   `json:"cdn_mode"`
	RunMode        string `json:"run_mode"`
	AppTitle       string `json:"title"`
	AppDescription string `json:"description"`

	// path to the directory where databases will be stored
	DBDir string `json:"database_dir"`

	AccountsBucket string `json:"accounts_bucket"`
	AccountsDB     string `json:"accounts_database"`
	DBExtension    string `json:"database_extension"`
	ProfilesBucket string `json:"profiles_bucket"`

	SessionName    string `json:"sessions_name"`
	SessionsDB     string `json:"sessions_database"`
	SessionsBucket string `json:"sessions_bucket"`
	SessMaxAge     int    `json:"sessions_max_age"`
	SessionPath    string `json:"session_path"`

	// The path to point to when login is success
	LoginRedirect string `json:"login_redirect"`

	ProfilePicField string `json:"profile_pic_field"`
	PhotosField     string `json:"photos_field"`

	MessagesBucket string `json:"messages_bucket"`

	TemplatesExtensions []string `json:"templates_extensions"`
	TemplatesDir        string   `json:"templates_dir"`
	DevMode             bool     `json:"dev_mode"`
}

RemixConfig contain configuration values for Remix

type Session

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

Session implemets gorilla session store interface

func NewSessStore

func NewSessStore(db nutz.Storage, bucket string, duration int, opts *sessions.Options, secrets ...[]byte) *Session

NewSessStore creates a new session store

func (*Session) Delete

func (s *Session) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Delete remove a session from database, and expires the cliet cookie

func (*Session) Get

func (s *Session) Get(r *http.Request, name string) (*sessions.Session, error)

Get retrieves a session

func (*Session) New

func (s *Session) New(r *http.Request, name string) (*sessions.Session, error)

New always returns a session, if the sessio is not found, a new one is created.

func (*Session) Save

func (s *Session) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save persist a session

type User

type User struct {
	UUID         string    `json:"uuid" gforms:"-"`
	FirstName    string    `json:"first_name" gforms:"first_name"`
	LastName     string    `json:"last_name" gforms:"last_name"`
	EmailAddress string    `json:"email" gforms:"email_address"`
	Pass         string    `json:"password" gforms:"pass"`
	ConfirmPass  string    `json:"-" gforms:"confirm_pass"`
	CreatedAt    time.Time `json:"created_at" gforms:"-"`
	UpdatedAt    time.Time `json:"updated_at" gforms:"-"`
}

User contains details about a user

func GetUser

func GetUser(db nutz.Storage, bucket, email string, nest ...string) (*User, error)

GetUser retrives a user.

func (*User) Email

func (u *User) Email() string

Email user email address

func (*User) Password

func (u *User) Password() string

Password user password

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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