polaris

package module
v0.0.0-...-c3af11c Latest Latest
Warning

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

Go to latest
Published: May 9, 2014 License: GPL-2.0 Imports: 21 Imported by: 0

README

Polaris

Polaris is my application starter in golang. It's not a framework but a integrated solution to mix in several existing components online.

Features
  • As you can see, Polaris is highly depends on go-martini/martini and its official extentionsmartini-contrib;
  • For data access, Polaris leverage robinmin/gorp which is an enhanced version based on coopernurse/gorp. It's an ORM-like databse access driver to enable the end user can access their database easily; it compact with the build in "database/sql", so it's easy to support your databse in case it's not supported so far;
  • Meanwhile, Polaris also embedded with the Redis driver so that you can store your session information and cache immediately;
Used Packages

Polaris try to integrated the following existing projects as the major compoents. Normally, you should set the environment variable GOPATH before you execute the following commands:

go get -u github.com/go-martini/martini
go get -u github.com/martini-contrib/binding
go get -u github.com/martini-contrib/encoder
go get -u github.com/martini-contrib/render
go get -u github.com/martini-contrib/throttle
go get -u github.com/martini-contrib/strict
go get -u github.com/martini-contrib/secure
go get -u github.com/martini-contrib/csrf
go get -u github.com/martini-contrib/accessflags
go get -u github.com/martini-contrib/gzip
go get -u github.com/martini-contrib/sessionauth
go get -u github.com/martini-contrib/cors
go get -u github.com/martini-contrib/oauth2
go get -u github.com/martini-contrib/acceptlang
go get -u github.com/martini-contrib/logstasher
go get -u github.com/martini-contrib/auth
go get -u github.com/martini-contrib/sessions
go get -u github.com/martini-contrib/method
go get -u github.com/martini-contrib/strip

go get -u github.com/robinmin/gorp
go get -u github.com/mattn/go-adodb
go get -u github.com/mattn/go-sqlite3
go get -u github.com/boj/redistore

go get -u github.com/robinmin/logo

Documentation

Overview

PolarisConfig defined the system configuration and router mapping. It's an interface to the end user to enable them to extend the capability.

Package polaris provides the major features to the end user. So far, it's a customized version of https://github.com/go-martini/martini/ with other packages. It proovides a solid project start in golang.

UserModel defined a user model. It's an interface to the end user to enable them to extend the capability.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateAnonymousUser

func GenerateAnonymousUser() sessionauth.User

GetAnonymousUser should generate an anonymous user model for all sessions. This should be an unauthenticated 0 value struct.

func Logger

func Logger() martini.Handler

Logger returns a middleware handler that logs the request as it goes in and the response as it goes out.

Types

type Config

type Config interface {
	LoadConfig() bool
	GetBasicConfig() *PolarisConfig
	RoterMap(app *PolarisApplication) bool
}

Config is the interface to cental config object

type DBConfig

type DBConfig struct {
	// Type is the type of database
	Type string
	// Driver is the driver name of current database, so far, Polaris support : mysql/gomysql/postgres/sqlite/adodb
	Driver string
	// Host is the host name of current database server
	Host string
	// Port is the port number of current database server
	Port string
	// Database is the database name of current database
	Database string
	// User is the user name to access current database
	User string
	// Password is the password of current user
	Password string
	// Verbose is flag to output SQL statement into log or not
	Verbose bool
	// LogFile is the log file name for SQL statement.
	LogFile string
	// contains filtered or unexported fields
}

func (*DBConfig) InitDB

func (conf *DBConfig) InitDB() *DBEngine

InitDB initialize a connection to specified database

func (*DBConfig) MartiniHandler

func (conf *DBConfig) MartiniHandler() martini.Handler

get handler for Martini.Use function

func (*DBConfig) String

func (conf *DBConfig) String() string

String is a helper to generate connection string for mssql

type DBEngine

type DBEngine struct {
	gorp.DbMap
}

func (*DBEngine) Close

func (egn *DBEngine) Close() bool

type PolarisApplication

type PolarisApplication struct {
	*martini.Martini
	martini.Router
	// Config is an user provided object to store relevant information
	Config Config
	// Store is a internal variable to store the RediStore object
	Store *redistore.RediStore
	// DbEngine is the pointer to a global query engine
	DbEngine *DBEngine
}

PolarisApplication represents a Martini with some reasonable defaults same as the original ClassicMartini.

func NewApp

func NewApp(cfg Config, newUser func() sessionauth.User) *PolarisApplication

NewApp creates a application object with some basic default middleware. It's based on ClassicMartini. Classic also maps martini.Routes as a service.

func (*PolarisApplication) Close

func (app *PolarisApplication) Close() bool

func (*PolarisApplication) RotateLog

func (app *PolarisApplication) RotateLog() bool

func (*PolarisApplication) RunApp

func (app *PolarisApplication) RunApp() bool

type PolarisConfig

type PolarisConfig struct {
	// DirStatic is the default folder name where the public resouces(e.g, image, css, js and etc) are putted into
	DirStatic string
	// DirTemplate is the folder name where the template files located in
	DirTemplate string
	// DirLog is the folder name where the log files located in
	DirLog string
	// TempExtension is the extension name of template files
	TempExtension string
	// TempEncoding is the encoding name of the templates files
	TempEncoding string
	// SessionStore is the store type of the session. it can be cookie or redis so far
	SessionStore string
	// SessionName is the default session name for cookie to store session id
	SessionName string
	// SessionMask is a mask code to the cookie of session id
	SessionMask string
	// Redis is the option set for redis connection
	Redis *RedisConfig
	// DBType is the datbase type. So far, it can be mysql/gomysql/postgres/sqlite/adodb
	DBType string
	// Database is the configuration items for database
	Database DBConfig

	// Port is the port number current server listening on
	Port int
	// CfgFile is a reference pointer to the config file
	CfgFile string
	// CfgHandle is a reference pointer to the config file
	CfgHandle *goconfig.ConfigFile

	// LogFile is the file name of current log
	LogFile string
	// LogHandle is the log handl
	LogHandle *os.File
	// contains filtered or unexported fields
}

PolarisConfig is the struct to define configuration items

func (*PolarisConfig) GetBasicConfig

func (cfg *PolarisConfig) GetBasicConfig() *PolarisConfig

func (*PolarisConfig) LoadConfig

func (cfg *PolarisConfig) LoadConfig() bool

LoadConfig creates a config object by specified config file.

func (*PolarisConfig) RoterMap

func (config *PolarisConfig) RoterMap(app *PolarisApplication) bool

RoterMap provides a interface to the end user to empower them to customize their own router

type RedisConfig

type RedisConfig struct {
	// Size is the maximum number of idle connections
	Size int
	// Network is the communication protocal of redis
	Network string
	// Address is the acctual adress of the redis server hostname + port
	Address string
	// Password is the default password of the connection
	Password string
	// DB is the default database in redis
	DB string
}

RedisConfig is the struct to define configuration items for redis

type UserModel

type UserModel struct {
	Uid        int64  `form:"Uid" db:"N_UID"`
	RoleID     int    `form:"-" db:"N_ROLE_ID"`
	Grp01      int    `form:"-" db:"N_GRP1"`
	Grp02      int    `form:"-" db:"N_GRP2"`
	InUse      int    `form:"-" db:"N_INUSE"`
	UserID     string `form:"UserID" db:"C_UID"`
	Password   string `form:"Password" db:"C_PWD"`
	Email      string `form:"-" db:"C_EMAIL"`
	HomeURL    string `form:"-" db:"C_HOME"`
	Language   string `form:"-" db:"C_LANGUAGE"`
	Org01      string `form:"-" db:"C_ORG1"`
	Org02      string `form:"-" db:"C_ORG2"`
	Org03      string `form:"-" db:"C_ORG3"`
	Org04      string `form:"-" db:"C_ORG4"`
	Preference string `form:"-" db:"C_PREFERENCE"`
	// contains filtered or unexported fields
}

UserModel can be any struct that represents a user in my system

func (*UserModel) GetById

func (u *UserModel) GetById(id interface{}) error

GetById will populate a user object from a database model with a matching id.

func (*UserModel) GetByNamePass

func (u *UserModel) GetByNamePass(strUserName string, strPass string) error

GetByNamePass will populate a user object from a database model with a matching name and password.

func (*UserModel) IsAuthenticated

func (u *UserModel) IsAuthenticated() bool

func (*UserModel) Login

func (u *UserModel) Login()

Login will preform any actions that are required to make a user model officially authenticated.

func (*UserModel) Logout

func (u *UserModel) Logout()

Logout will preform any actions that are required to completely logout a user.

func (*UserModel) UniqueId

func (u *UserModel) UniqueId() interface{}

Jump to

Keyboard shortcuts

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