kinli

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

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

Go to latest
Published: Oct 1, 2017 License: MIT Imports: 17 Imported by: 1

README

GoDoc

Go Versions

Tested on Go versions > 1.6

Installation

go get github.com/sairam/kinli

or

dep ensure -add github.com/sairam/kinli

Using kinli

  • kinli.PathTemplate
  • kinli.PathPartialTemplate
  • kinli.CacheMode - true or false based on production / dev
  • kinli.ViewFuncs - additional list of ViewFuncs you'd like to access from views
  • kinli.InitTmpl() - to start your template rendering
  • kinli.SessionStore - this is a mandatory field to be initialized

Sending Emails

var smtpConfig = &kinli.EmailSMTPConfig{config.SMTPHost, config.SMTPPort, config.SMTPUser, config.SMTPPass}
kinli.InitMailer(smtpConfig)

e := &kinli.EmailCtx{} // fill up the fields from,to, subject, TextBody, HTMLBody, optional headers
e.SendEmail()

Example

See example1/ for a quick webpage

What is kinli?

kinli is a code wrapper extracted for creating simple web pages quicker

  • Helper functions come in as requirements come. All helper functions are taken from hugo project
  • repeating methods on top of sessions using the gorilla/sessions

This code is extracted from GitNotify

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SessionName ..
	SessionName = "_kinli" // can be seen in the cookies list

	// HomePathNonAuthed redirection for NonLoggedInUser
	HomePathNonAuthed = "/home"

	// HomePathAuthed redirection for LoggedInUser
	HomePathAuthed = "/"

	// SessionStore interface to will be used
	SessionStore sessions.Store
)
View Source
var (
	// PathTemplate is the template/ dir . default is tmpl/
	PathTemplate = "tmpl/"
	// PathPartialTemplate is the relative path for partials/ directory. default is tmpl/partials/
	PathPartialTemplate = "tmpl/partials/"
	// CacheMode is true to cache templates. set to false during development
	CacheMode = true
	// ViewFuncs supports extra functions which user can use in views
	ViewFuncs template.FuncMap
)
View Source
var (
	// ClientConfig can be set once so that all pages can use that static information
	ClientConfig map[string]string
)

hc.isAuthed() { userInfo = &Authentication{}

View Source
var IsAuthed = isAuthed

IsAuthed is used to verify if a user is logged in or not can be overriden with your own business logic

Functions

func DisplayPage

func DisplayPage(w io.Writer, path string, page interface{})

DisplayPage exposes writer path is the name of the file without ".html" page can be the structure that you can access in the view. Page struct is recommended or inherit the Page struct

func DisplayText

func DisplayText(hc *HttpContext, w io.Writer, text string)

DisplayText takes in the context for creating a NewPage and displays the text as page Uses "_text.html" file in your template directory

func GetPage

func GetPage(path string, page interface{}) io.Reader

GetPage gets the raw page content

func GetPageContent

func GetPageContent(path string, page interface{}) (string, error)

GetPageContent gets the page content as string

func InitMailer

func InitMailer(smtpConfig *EmailSMTPConfig)

InitMailer can be initialised only once all future calls will be ignored

func InitTmpl

func InitTmpl()

InitTmpl should be called after any of the Template variables are modified

Types

type EmailCtx

type EmailCtx struct {
	From      *mail.Address
	To        []*mail.Address
	Cc        []*mail.Address
	Bcc       []*mail.Address
	Subject   string
	PlainBody string
	HTMLBody  string

	// optional headers that need to be sent
	Headers map[string]string
}

EmailCtx which needs to be set to send the email

func (*EmailCtx) MakeEmail

func (ctx *EmailCtx) MakeEmail() *gomail.Message

MakeEmail makes a gomail.Message to be sent

func (*EmailCtx) SendEmail

func (ctx *EmailCtx) SendEmail()

SendEmail to be called for making and sending the email Never invoke SendEmail without calling InitMailer exactly once

type EmailSMTPConfig

type EmailSMTPConfig struct {
	Host string
	Port int
	User string
	Pass string
}

EmailSMTPConfig passed for initialisation

type HttpContext

type HttpContext struct {
	W http.ResponseWriter
	R *http.Request
}

HttpContext .. is the current context

func (*HttpContext) AddFlash

func (hc *HttpContext) AddFlash(flash string)

func (*HttpContext) ClearSession

func (hc *HttpContext) ClearSession()

ClearSession logs out the user by deleting all session data

func (*HttpContext) GetFlashes

func (hc *HttpContext) GetFlashes() []string

GetFlashes gets the list of flashes and flushes as well

func (*HttpContext) GetSessionData

func (hc *HttpContext) GetSessionData(key string) interface{}

GetSessionData can be used to retrieve the data retrieving should be of the format data, ok := val.(*Data)

func (*HttpContext) RedirectAfterAuth

func (hc *HttpContext) RedirectAfterAuth(flash string) bool

RedirectAfterAuth will redirect user immediately after authentication returns true if redirected, false if not

func (*HttpContext) RedirectUnlessAuthed

func (hc *HttpContext) RedirectUnlessAuthed(flash string) bool

RedirectUnlessAuthed redirects if the user is not logged in returns true if redirected, false if not

func (*HttpContext) SetSessionData

func (hc *HttpContext) SetSessionData(key string, value interface{})

setSessionData sets a key/value into a session and saves it value should be registered first with gob.Register(&Data{}) should be sending data should be of the format ("data", &Data{}) retrieving should be of the format data, ok := val.(*Data)

type Page

type Page struct {
	// Title of the page
	Title string // TODO make this richer context
	// User information that can be accessed on any page
	User interface{}
	// List of Flash Messages
	Flashes []string // List of flash messages
	// Context is the Main Content of the page
	Context interface{}
	// Data not part of the context (one timers info)
	Data map[string]string
	// ClientConfig contains constant stuff like GoogleAnalytics attributes etc.,
	ClientConfig map[string]string
}

Page has all information to be fillable

func NewPage

func NewPage(hc *HttpContext, title string, user interface{}, ctx interface{}, data map[string]string) *Page

NewPage is used by all HTML contexts to display the template Emails do not use Pages. Only for views

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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