mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +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
|
||||
- osx
|
||||
go:
|
||||
- "go1.9"
|
||||
- "go1.10"
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
go_import_path: github.com/kataras/iris
|
||||
# we disable test caching via GOCACHE=off
|
||||
env:
|
||||
global:
|
||||
- GOCACHE=off
|
||||
# env:
|
||||
# global:
|
||||
# - GOCACHE=off
|
||||
install:
|
||||
- go get ./... # for iris-contrib/httpexpect, kataras/golog
|
||||
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)
|
||||
- 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
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"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
|
||||
|
@ -28,17 +28,17 @@ var (
|
|||
// 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.
|
||||
type DB struct {
|
||||
db *bbolt.DB
|
||||
db *bolt.DB
|
||||
}
|
||||
|
||||
var _ Store = &DB{}
|
||||
|
||||
// openDatabase open a new database connection
|
||||
// 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.
|
||||
// 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 {
|
||||
Panic(err)
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func openDatabase(stumb string) *bbolt.DB {
|
|||
tableURLs,
|
||||
}
|
||||
|
||||
db.Update(func(tx *bbolt.Tx) (err error) {
|
||||
db.Update(func(tx *bolt.Tx) (err error) {
|
||||
for _, table := range tables {
|
||||
_, err = tx.CreateBucketIfNotExists(table)
|
||||
if err != nil {
|
||||
|
@ -73,7 +73,7 @@ func NewDB(stumb string) *DB {
|
|||
// Set sets a shorten url and its key
|
||||
// Note: Caller is responsible to generate a key.
|
||||
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)
|
||||
// Generate ID for the url
|
||||
// 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.
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ func (d *DB) Clear() error {
|
|||
// Returns an empty string if not found.
|
||||
func (d *DB) Get(key string) (value string) {
|
||||
keyB := []byte(key)
|
||||
d.db.Update(func(tx *bbolt.Tx) error {
|
||||
d.db.Update(func(tx *bolt.Tx) error {
|
||||
b := tx.Bucket(tableURLs)
|
||||
if b == 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.
|
||||
func (d *DB) GetByValue(value string) (keys []string) {
|
||||
valueB := []byte(value)
|
||||
d.db.Update(func(tx *bbolt.Tx) error {
|
||||
d.db.Update(func(tx *bolt.Tx) error {
|
||||
b := tx.Bucket(tableURLs)
|
||||
if b == nil {
|
||||
return nil
|
||||
|
@ -159,7 +159,7 @@ func (d *DB) GetByValue(value string) (keys []string) {
|
|||
|
||||
// Len returns all the "shorted" urls length
|
||||
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
|
||||
b := tx.Bucket(tableURLs)
|
||||
|
|
|
@ -6,10 +6,11 @@ import (
|
|||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/etcd-io/bbolt"
|
||||
"github.com/kataras/golog"
|
||||
"github.com/kataras/iris/core/errors"
|
||||
"github.com/kataras/iris/sessions"
|
||||
|
||||
bolt "github.com/etcd-io/bbolt"
|
||||
"github.com/kataras/golog"
|
||||
)
|
||||
|
||||
// DefaultFileMode used as the default database's "fileMode"
|
||||
|
@ -25,7 +26,7 @@ type Database struct {
|
|||
// Service is the underline BoltDB database connection,
|
||||
// it's initialized at `New` or `NewFromDB`.
|
||||
// Can be used to get stats.
|
||||
Service *bbolt.DB
|
||||
Service *bolt.DB
|
||||
}
|
||||
|
||||
var errPathMissing = errors.New("path is required")
|
||||
|
@ -51,8 +52,8 @@ func New(path string, fileMode os.FileMode) (*Database, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
service, err := bbolt.Open(path, fileMode,
|
||||
&bbolt.Options{Timeout: 20 * time.Second},
|
||||
service, err := bolt.Open(path, fileMode,
|
||||
&bolt.Options{Timeout: 20 * time.Second},
|
||||
)
|
||||
|
||||
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.
|
||||
func NewFromDB(service *bbolt.DB, bucketName string) (*Database, error) {
|
||||
func NewFromDB(service *bolt.DB, bucketName string) (*Database, error) {
|
||||
bucket := []byte(bucketName)
|
||||
|
||||
service.Update(func(tx *bbolt.Tx) (err error) {
|
||||
service.Update(func(tx *bolt.Tx) (err error) {
|
||||
_, err = tx.CreateBucketIfNotExists(bucket)
|
||||
return
|
||||
})
|
||||
|
@ -78,15 +79,15 @@ func NewFromDB(service *bbolt.DB, bucketName string) (*Database, error) {
|
|||
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)
|
||||
}
|
||||
|
||||
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))
|
||||
if b == nil {
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
@ -105,7 +106,7 @@ func getExpirationBucketName(bsid []byte) []byte {
|
|||
|
||||
// Cleanup removes any invalid(have expired) session entries on initialization.
|
||||
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)
|
||||
c := b.Cursor()
|
||||
// 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.
|
||||
func (db *Database) Acquire(sid string, expires time.Duration) (lifetime sessions.LifeTime) {
|
||||
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)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
err = db.Service.Update(func(tx *bbolt.Tx) error {
|
||||
err = db.Service.Update(func(tx *bolt.Tx) error {
|
||||
expirationName := getExpirationBucketName([]byte(sid))
|
||||
root := db.getBucket(tx)
|
||||
b := root.Bucket(expirationName)
|
||||
|
@ -250,7 +251,7 @@ func (db *Database) Set(sid string, lifetime sessions.LifeTime, key string, valu
|
|||
return
|
||||
}
|
||||
|
||||
err = db.Service.Update(func(tx *bbolt.Tx) error {
|
||||
err = db.Service.Update(func(tx *bolt.Tx) error {
|
||||
b := db.getBucketForSession(tx, sid)
|
||||
if b == 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.
|
||||
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)
|
||||
if b == 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.
|
||||
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)
|
||||
if b == 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).
|
||||
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)
|
||||
if b == 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.
|
||||
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)
|
||||
if b == nil {
|
||||
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.
|
||||
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)
|
||||
if b == nil {
|
||||
return nil
|
||||
|
@ -358,7 +359,7 @@ func (db *Database) Clear(sid string) {
|
|||
// 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.
|
||||
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.
|
||||
b := db.getBucket(tx)
|
||||
bsid := []byte(sid)
|
||||
|
|
Loading…
Reference in New Issue
Block a user