mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 23:40:35 +01:00
go modules and vendoring section explain why not yet, in my opinion let's stick with the current system until gophers get acquainted with the new go modules and how it works - I putted a link to the TOC in order to help them
Former-commit-id: 572527152de5808c834546ca1373de716046770e
This commit is contained in:
parent
e6bd3c1f0c
commit
4fd9886a10
11
.travis.yml
11
.travis.yml
|
@ -3,13 +3,14 @@ os:
|
||||||
- linux
|
- linux
|
||||||
- osx
|
- osx
|
||||||
go:
|
go:
|
||||||
- "go1.9"
|
- 1.9.x
|
||||||
- "go1.10"
|
- 1.10.x
|
||||||
|
- 1.11.x
|
||||||
go_import_path: github.com/kataras/iris
|
go_import_path: github.com/kataras/iris
|
||||||
# we disable test caching via GOCACHE=off
|
# we disable test caching via GOCACHE=off
|
||||||
env:
|
# env:
|
||||||
global:
|
# global:
|
||||||
- GOCACHE=off
|
# - GOCACHE=off
|
||||||
install:
|
install:
|
||||||
- go get ./... # for iris-contrib/httpexpect, kataras/golog
|
- go get ./... # for iris-contrib/httpexpect, kataras/golog
|
||||||
script:
|
script:
|
||||||
|
|
|
@ -80,7 +80,8 @@ app.Get("/profile/{name:alphabetical max(255)}", func(ctx iris.Context){
|
||||||
- Rename the vendor `sessions/sessiondb/vendor/...bbolt` from `coreos/bbolt` to `etcd-io/bbolt` and update to v1.3.1, based on [that](https://github.com/etcd-io/bbolt/releases/tag/v1.3.1-etcd.7)
|
- Rename the vendor `sessions/sessiondb/vendor/...bbolt` from `coreos/bbolt` to `etcd-io/bbolt` and update to v1.3.1, based on [that](https://github.com/etcd-io/bbolt/releases/tag/v1.3.1-etcd.7)
|
||||||
- Update the vendor `sessions/sessiondb/vendor/...badger` to v1.5.3
|
- Update the vendor `sessions/sessiondb/vendor/...badger` to v1.5.3
|
||||||
|
|
||||||
> More to come, maybe it will be removed eventually.
|
I believe it is soon to adapt the new [go modules](https://github.com/golang/go/wiki/Modules#table-of-contents) inside Iris, the new `go mod` command may change until go 1.12, it is still an experimental feature.
|
||||||
|
The [vendor](https://github.com/kataras/iris/tree/v11/vendor) folder will be kept until most the majority of Go developers get acquainted with the new `go modules`. The `go.mod` and `go.sum` files will come at `iris v12` (or `go 1.12`), we could do that on this version as well but I don't want to have half-things, versioning should be passed on import path as well and that is a large breaking change to go with it right now, so it will probably have a new path such as `github.com/kataras/iris/v12` based on a `git tag` like every Iris release (we are lucky here because we used semantic versioning from day zero). No folder re-structure inside the root git repository to split versions will ever happen, so backwards-compatibility will be not enabled by-default although it's easy for anyone to grab any version from older [releases](https://github.com/kataras/iris/releases) or branch and target that.
|
||||||
|
|
||||||
# Sat, 11 August 2018 | v10.7.0
|
# Sat, 11 August 2018 | v10.7.0
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
"github.com/etcd-io/bbolt"
|
bolt "github.com/etcd-io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Panic panics, change it if you don't want to panic on critical INITIALIZE-ONLY-ERRORS
|
// Panic panics, change it if you don't want to panic on critical INITIALIZE-ONLY-ERRORS
|
||||||
|
@ -28,17 +28,17 @@ var (
|
||||||
// Only one table/bucket which contains the urls, so it's not a fully Database,
|
// Only one table/bucket which contains the urls, so it's not a fully Database,
|
||||||
// it works only with single bucket because that all we need.
|
// it works only with single bucket because that all we need.
|
||||||
type DB struct {
|
type DB struct {
|
||||||
db *bbolt.DB
|
db *bolt.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Store = &DB{}
|
var _ Store = &DB{}
|
||||||
|
|
||||||
// openDatabase open a new database connection
|
// openDatabase open a new database connection
|
||||||
// and returns its instance.
|
// and returns its instance.
|
||||||
func openDatabase(stumb string) *bbolt.DB {
|
func openDatabase(stumb string) *bolt.DB {
|
||||||
// Open the data(base) file in the current working directory.
|
// Open the data(base) file in the current working directory.
|
||||||
// It will be created if it doesn't exist.
|
// It will be created if it doesn't exist.
|
||||||
db, err := bbolt.Open(stumb, 0600, nil)
|
db, err := bolt.Open(stumb, 0600, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Panic(err)
|
Panic(err)
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func openDatabase(stumb string) *bbolt.DB {
|
||||||
tableURLs,
|
tableURLs,
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Update(func(tx *bbolt.Tx) (err error) {
|
db.Update(func(tx *bolt.Tx) (err error) {
|
||||||
for _, table := range tables {
|
for _, table := range tables {
|
||||||
_, err = tx.CreateBucketIfNotExists(table)
|
_, err = tx.CreateBucketIfNotExists(table)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -73,7 +73,7 @@ func NewDB(stumb string) *DB {
|
||||||
// Set sets a shorten url and its key
|
// Set sets a shorten url and its key
|
||||||
// Note: Caller is responsible to generate a key.
|
// Note: Caller is responsible to generate a key.
|
||||||
func (d *DB) Set(key string, value string) error {
|
func (d *DB) Set(key string, value string) error {
|
||||||
return d.db.Update(func(tx *bbolt.Tx) error {
|
return d.db.Update(func(tx *bolt.Tx) error {
|
||||||
b, err := tx.CreateBucketIfNotExists(tableURLs)
|
b, err := tx.CreateBucketIfNotExists(tableURLs)
|
||||||
// Generate ID for the url
|
// Generate ID for the url
|
||||||
// Note: we could use that instead of a random string key
|
// Note: we could use that instead of a random string key
|
||||||
|
@ -106,7 +106,7 @@ func (d *DB) Set(key string, value string) error {
|
||||||
|
|
||||||
// Clear clears all the database entries for the table urls.
|
// Clear clears all the database entries for the table urls.
|
||||||
func (d *DB) Clear() error {
|
func (d *DB) Clear() error {
|
||||||
return d.db.Update(func(tx *bbolt.Tx) error {
|
return d.db.Update(func(tx *bolt.Tx) error {
|
||||||
return tx.DeleteBucket(tableURLs)
|
return tx.DeleteBucket(tableURLs)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ func (d *DB) Clear() error {
|
||||||
// Returns an empty string if not found.
|
// Returns an empty string if not found.
|
||||||
func (d *DB) Get(key string) (value string) {
|
func (d *DB) Get(key string) (value string) {
|
||||||
keyB := []byte(key)
|
keyB := []byte(key)
|
||||||
d.db.Update(func(tx *bbolt.Tx) error {
|
d.db.Update(func(tx *bolt.Tx) error {
|
||||||
b := tx.Bucket(tableURLs)
|
b := tx.Bucket(tableURLs)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -138,7 +138,7 @@ func (d *DB) Get(key string) (value string) {
|
||||||
// GetByValue returns all keys for a specific (original) url value.
|
// GetByValue returns all keys for a specific (original) url value.
|
||||||
func (d *DB) GetByValue(value string) (keys []string) {
|
func (d *DB) GetByValue(value string) (keys []string) {
|
||||||
valueB := []byte(value)
|
valueB := []byte(value)
|
||||||
d.db.Update(func(tx *bbolt.Tx) error {
|
d.db.Update(func(tx *bolt.Tx) error {
|
||||||
b := tx.Bucket(tableURLs)
|
b := tx.Bucket(tableURLs)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -159,7 +159,7 @@ func (d *DB) GetByValue(value string) (keys []string) {
|
||||||
|
|
||||||
// Len returns all the "shorted" urls length
|
// Len returns all the "shorted" urls length
|
||||||
func (d *DB) Len() (num int) {
|
func (d *DB) Len() (num int) {
|
||||||
d.db.View(func(tx *bbolt.Tx) error {
|
d.db.View(func(tx *bolt.Tx) error {
|
||||||
|
|
||||||
// Assume bucket exists and has keys
|
// Assume bucket exists and has keys
|
||||||
b := tx.Bucket(tableURLs)
|
b := tx.Bucket(tableURLs)
|
||||||
|
|
|
@ -6,10 +6,11 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/etcd-io/bbolt"
|
|
||||||
"github.com/kataras/golog"
|
|
||||||
"github.com/kataras/iris/core/errors"
|
"github.com/kataras/iris/core/errors"
|
||||||
"github.com/kataras/iris/sessions"
|
"github.com/kataras/iris/sessions"
|
||||||
|
|
||||||
|
bolt "github.com/etcd-io/bbolt"
|
||||||
|
"github.com/kataras/golog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultFileMode used as the default database's "fileMode"
|
// DefaultFileMode used as the default database's "fileMode"
|
||||||
|
@ -25,7 +26,7 @@ type Database struct {
|
||||||
// Service is the underline BoltDB database connection,
|
// Service is the underline BoltDB database connection,
|
||||||
// it's initialized at `New` or `NewFromDB`.
|
// it's initialized at `New` or `NewFromDB`.
|
||||||
// Can be used to get stats.
|
// Can be used to get stats.
|
||||||
Service *bbolt.DB
|
Service *bolt.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
var errPathMissing = errors.New("path is required")
|
var errPathMissing = errors.New("path is required")
|
||||||
|
@ -51,8 +52,8 @@ func New(path string, fileMode os.FileMode) (*Database, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
service, err := bbolt.Open(path, fileMode,
|
service, err := bolt.Open(path, fileMode,
|
||||||
&bbolt.Options{Timeout: 20 * time.Second},
|
&bolt.Options{Timeout: 20 * time.Second},
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -64,10 +65,10 @@ func New(path string, fileMode os.FileMode) (*Database, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFromDB same as `New` but accepts an already-created custom boltdb connection instead.
|
// NewFromDB same as `New` but accepts an already-created custom boltdb connection instead.
|
||||||
func NewFromDB(service *bbolt.DB, bucketName string) (*Database, error) {
|
func NewFromDB(service *bolt.DB, bucketName string) (*Database, error) {
|
||||||
bucket := []byte(bucketName)
|
bucket := []byte(bucketName)
|
||||||
|
|
||||||
service.Update(func(tx *bbolt.Tx) (err error) {
|
service.Update(func(tx *bolt.Tx) (err error) {
|
||||||
_, err = tx.CreateBucketIfNotExists(bucket)
|
_, err = tx.CreateBucketIfNotExists(bucket)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
@ -78,15 +79,15 @@ func NewFromDB(service *bbolt.DB, bucketName string) (*Database, error) {
|
||||||
return db, db.cleanup()
|
return db, db.cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Database) getBucket(tx *bbolt.Tx) *bbolt.Bucket {
|
func (db *Database) getBucket(tx *bolt.Tx) *bolt.Bucket {
|
||||||
return tx.Bucket(db.table)
|
return tx.Bucket(db.table)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Database) getBucketForSession(tx *bbolt.Tx, sid string) *bbolt.Bucket {
|
func (db *Database) getBucketForSession(tx *bolt.Tx, sid string) *bolt.Bucket {
|
||||||
b := db.getBucket(tx).Bucket([]byte(sid))
|
b := db.getBucket(tx).Bucket([]byte(sid))
|
||||||
if b == nil {
|
if b == nil {
|
||||||
// session does not exist, it shouldn't happen, session bucket creation happens once at `Acquire`,
|
// session does not exist, it shouldn't happen, session bucket creation happens once at `Acquire`,
|
||||||
// no need to accept the `bbolt.bucket.CreateBucketIfNotExists`'s performance cost.
|
// no need to accept the `bolt.bucket.CreateBucketIfNotExists`'s performance cost.
|
||||||
golog.Debugf("unreachable session access for '%s'", sid)
|
golog.Debugf("unreachable session access for '%s'", sid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +106,7 @@ func getExpirationBucketName(bsid []byte) []byte {
|
||||||
|
|
||||||
// Cleanup removes any invalid(have expired) session entries on initialization.
|
// Cleanup removes any invalid(have expired) session entries on initialization.
|
||||||
func (db *Database) cleanup() error {
|
func (db *Database) cleanup() error {
|
||||||
return db.Service.Update(func(tx *bbolt.Tx) error {
|
return db.Service.Update(func(tx *bolt.Tx) error {
|
||||||
b := db.getBucket(tx)
|
b := db.getBucket(tx)
|
||||||
c := b.Cursor()
|
c := b.Cursor()
|
||||||
// loop through all buckets, find one with expiration.
|
// loop through all buckets, find one with expiration.
|
||||||
|
@ -151,7 +152,7 @@ var expirationKey = []byte("exp") // it can be random.
|
||||||
// if the return value is LifeTime{} then the session manager sets the life time based on the expiration duration lives in configuration.
|
// if the return value is LifeTime{} then the session manager sets the life time based on the expiration duration lives in configuration.
|
||||||
func (db *Database) Acquire(sid string, expires time.Duration) (lifetime sessions.LifeTime) {
|
func (db *Database) Acquire(sid string, expires time.Duration) (lifetime sessions.LifeTime) {
|
||||||
bsid := []byte(sid)
|
bsid := []byte(sid)
|
||||||
err := db.Service.Update(func(tx *bbolt.Tx) (err error) {
|
err := db.Service.Update(func(tx *bolt.Tx) (err error) {
|
||||||
root := db.getBucket(tx)
|
root := db.getBucket(tx)
|
||||||
|
|
||||||
if expires > 0 { // should check or create the expiration bucket.
|
if expires > 0 { // should check or create the expiration bucket.
|
||||||
|
@ -218,7 +219,7 @@ func (db *Database) OnUpdateExpiration(sid string, newExpires time.Duration) err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.Service.Update(func(tx *bbolt.Tx) error {
|
err = db.Service.Update(func(tx *bolt.Tx) error {
|
||||||
expirationName := getExpirationBucketName([]byte(sid))
|
expirationName := getExpirationBucketName([]byte(sid))
|
||||||
root := db.getBucket(tx)
|
root := db.getBucket(tx)
|
||||||
b := root.Bucket(expirationName)
|
b := root.Bucket(expirationName)
|
||||||
|
@ -250,7 +251,7 @@ func (db *Database) Set(sid string, lifetime sessions.LifeTime, key string, valu
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.Service.Update(func(tx *bbolt.Tx) error {
|
err = db.Service.Update(func(tx *bolt.Tx) error {
|
||||||
b := db.getBucketForSession(tx, sid)
|
b := db.getBucketForSession(tx, sid)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -270,7 +271,7 @@ func (db *Database) Set(sid string, lifetime sessions.LifeTime, key string, valu
|
||||||
|
|
||||||
// Get retrieves a session value based on the key.
|
// Get retrieves a session value based on the key.
|
||||||
func (db *Database) Get(sid string, key string) (value interface{}) {
|
func (db *Database) Get(sid string, key string) (value interface{}) {
|
||||||
err := db.Service.View(func(tx *bbolt.Tx) error {
|
err := db.Service.View(func(tx *bolt.Tx) error {
|
||||||
b := db.getBucketForSession(tx, sid)
|
b := db.getBucketForSession(tx, sid)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -293,7 +294,7 @@ func (db *Database) Get(sid string, key string) (value interface{}) {
|
||||||
|
|
||||||
// Visit loops through all session keys and values.
|
// Visit loops through all session keys and values.
|
||||||
func (db *Database) Visit(sid string, cb func(key string, value interface{})) {
|
func (db *Database) Visit(sid string, cb func(key string, value interface{})) {
|
||||||
db.Service.View(func(tx *bbolt.Tx) error {
|
db.Service.View(func(tx *bolt.Tx) error {
|
||||||
b := db.getBucketForSession(tx, sid)
|
b := db.getBucketForSession(tx, sid)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -314,7 +315,7 @@ func (db *Database) Visit(sid string, cb func(key string, value interface{})) {
|
||||||
|
|
||||||
// Len returns the length of the session's entries (keys).
|
// Len returns the length of the session's entries (keys).
|
||||||
func (db *Database) Len(sid string) (n int) {
|
func (db *Database) Len(sid string) (n int) {
|
||||||
db.Service.View(func(tx *bbolt.Tx) error {
|
db.Service.View(func(tx *bolt.Tx) error {
|
||||||
b := db.getBucketForSession(tx, sid)
|
b := db.getBucketForSession(tx, sid)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -329,7 +330,7 @@ func (db *Database) Len(sid string) (n int) {
|
||||||
|
|
||||||
// Delete removes a session key value based on its key.
|
// Delete removes a session key value based on its key.
|
||||||
func (db *Database) Delete(sid string, key string) (deleted bool) {
|
func (db *Database) Delete(sid string, key string) (deleted bool) {
|
||||||
err := db.Service.Update(func(tx *bbolt.Tx) error {
|
err := db.Service.Update(func(tx *bolt.Tx) error {
|
||||||
b := db.getBucketForSession(tx, sid)
|
b := db.getBucketForSession(tx, sid)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return sessions.ErrNotFound
|
return sessions.ErrNotFound
|
||||||
|
@ -343,7 +344,7 @@ func (db *Database) Delete(sid string, key string) (deleted bool) {
|
||||||
|
|
||||||
// Clear removes all session key values but it keeps the session entry.
|
// Clear removes all session key values but it keeps the session entry.
|
||||||
func (db *Database) Clear(sid string) {
|
func (db *Database) Clear(sid string) {
|
||||||
db.Service.Update(func(tx *bbolt.Tx) error {
|
db.Service.Update(func(tx *bolt.Tx) error {
|
||||||
b := db.getBucketForSession(tx, sid)
|
b := db.getBucketForSession(tx, sid)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -358,7 +359,7 @@ func (db *Database) Clear(sid string) {
|
||||||
// Release destroys the session, it clears and removes the session entry,
|
// Release destroys the session, it clears and removes the session entry,
|
||||||
// session manager will create a new session ID on the next request after this call.
|
// session manager will create a new session ID on the next request after this call.
|
||||||
func (db *Database) Release(sid string) {
|
func (db *Database) Release(sid string) {
|
||||||
db.Service.Update(func(tx *bbolt.Tx) error {
|
db.Service.Update(func(tx *bolt.Tx) error {
|
||||||
// delete the session bucket.
|
// delete the session bucket.
|
||||||
b := db.getBucket(tx)
|
b := db.getBucket(tx)
|
||||||
bsid := []byte(sid)
|
bsid := []byte(sid)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user