engine

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2017 License: Apache-2.0 Imports: 3 Imported by: 20

README

Session

Middleware support for echo, utilizing by admpub/sessions.

Installation

go get github.com/webx-top/echo

Usage

package main

import (
    "github.com/webx-top/echo"
    "github.com/webx-top/echo/engine/standard"
    "github.com/webx-top/echo/middleware/session"
    cookieStore "github.com/webx-top/echo/middleware/session/engine/cookie"
)

func index(c echo.Context) error {
    session := c.Session()

    var count int
    v := session.Get("count")

    if v == nil {
        count = 0
    } else {
        count = v.(int)
        count += 1
    }

    session.Set("count", count)

    data := struct {
        Visit int
    }{
        Visit: count,
    }

    return c.JSON(http.StatusOK, data)
}

func main() {
    sessionOptions:=&echo.SessionOptions{
        Name:   `GOSESSIONID`,
        Engine: `cookie`,
        CookieOptions: &echo.CookieOptions{
            Path:     `/`,
            HttpOnly: true,
        },
    }
    cookieStore.RegWithOptions(&cookieStore.CookieOptions{
        KeyPairs: [][]byte{
            []byte("secret-key"),
        },
        SessionOptions: sessionOptions,
    })

    e := echo.New()

    // Attach middleware
    e.Use(session.Middleware(sessionOptions))

    // Routes
    e.Get("/", index)

    e.Run(standard.New(":8080"))
}

Documentation

Overview

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Session implements middleware for easily using github.com/gorilla/sessions within echo. This package was originally inspired from the https://github.com/ipfans/echo-session package, and modified to provide more functionality

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Del

func Del(name string)

func NewMySession

func NewMySession(store Store, name string, ctx echo.Context) echo.Sessioner

func NewSession

func NewSession(options *echo.SessionOptions, ctx echo.Context) echo.Sessioner

func Reg

func Reg(name string, store Store)

Types

type Session

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

func (*Session) AddFlash

func (s *Session) AddFlash(value interface{}, vars ...string) echo.Sessioner

func (*Session) Clear

func (s *Session) Clear() echo.Sessioner

func (*Session) Delete

func (s *Session) Delete(key string) echo.Sessioner

func (*Session) Flashes

func (s *Session) Flashes(vars ...string) []interface{}

func (*Session) Get

func (s *Session) Get(key string) interface{}

func (*Session) Id

func (s *Session) Id() string

func (*Session) Options

func (s *Session) Options(options echo.SessionOptions) echo.Sessioner

func (*Session) Save

func (s *Session) Save() error

func (*Session) Session

func (s *Session) Session() *sessions.Session

func (*Session) Set

func (s *Session) Set(key string, val interface{}) echo.Sessioner

func (*Session) SetId

func (s *Session) SetId(id string) echo.Sessioner

func (*Session) Written

func (s *Session) Written() bool

type Store

type Store interface {
	sessions.Store
	Options(echo.SessionOptions)
}

func Get

func Get(name string) Store

func StoreEngine

func StoreEngine(options *echo.SessionOptions) (store Store)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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