mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
add a new 'overview' MVC example
Former-commit-id: f73cbf6010595c639f6c5b5119e2ec41bc9802a5
This commit is contained in:
22
_examples/mvc/overview/database/database.go
Normal file
22
_examples/mvc/overview/database/database.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"app/environment"
|
||||
)
|
||||
|
||||
// DB example database interface.
|
||||
type DB interface {
|
||||
Exec(q string) error
|
||||
}
|
||||
|
||||
// NewDB returns a database based on "env".
|
||||
func NewDB(env environment.Env) DB {
|
||||
switch env {
|
||||
case environment.PROD:
|
||||
return &mysql{}
|
||||
case environment.DEV:
|
||||
return &sqlite{}
|
||||
default:
|
||||
panic("unknown environment")
|
||||
}
|
||||
}
|
||||
10
_examples/mvc/overview/database/mysql.go
Normal file
10
_examples/mvc/overview/database/mysql.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package database
|
||||
|
||||
import "fmt"
|
||||
|
||||
type mysql struct{}
|
||||
|
||||
func (db *mysql) Exec(q string) error {
|
||||
// simulate an error response.
|
||||
return fmt.Errorf("mysql: not implemented <%s>", q)
|
||||
}
|
||||
5
_examples/mvc/overview/database/sqlite.go
Normal file
5
_examples/mvc/overview/database/sqlite.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package database
|
||||
|
||||
type sqlite struct{}
|
||||
|
||||
func (db *sqlite) Exec(q string) error { return nil }
|
||||
Reference in New Issue
Block a user