mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 13:05:56 +00:00
let's see
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
* [MySQL, Groupcache & Docker](database/mysql)
|
||||
* [MongoDB](database/mongodb)
|
||||
* [Sqlx](database/orm/sqlx/main.go)
|
||||
* [Xorm](database/orm/xorm/main.go)
|
||||
* [Gorm](database/orm/gorm/main.go)
|
||||
* [Reform](database/orm/reform/main.go)
|
||||
* HTTP Server
|
||||
|
||||
@@ -14,7 +14,7 @@ $ docker-compose up --build
|
||||
|
||||
### Install (Manually)
|
||||
|
||||
Run `go build` or `go run main.go` and read below.
|
||||
Run `go build -mod=mod` or `go run -mod=mod main.go` and read below.
|
||||
|
||||
#### MySQL
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ $ docker-compose up --build
|
||||
|
||||
### Install (Manually)
|
||||
|
||||
Run `go build` or `go run main.go` and read below.
|
||||
Run `go build -mod=mod` or `go run -mod=mod main.go` and read below.
|
||||
|
||||
#### MySQL
|
||||
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
// Package main shows how an orm can be used within your web app
|
||||
// it just inserts a column and select the first.
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
/*
|
||||
go get -u github.com/mattn/go-sqlite3
|
||||
go get -u xorm.io/xorm
|
||||
|
||||
If you're on win64 and you can't install go-sqlite3:
|
||||
1. Download: https://sourceforge.net/projects/mingw-w64/files/latest/download
|
||||
2. Select "x86_x64" and "posix"
|
||||
3. Add C:\Program Files\mingw-w64\x86_64-7.1.0-posix-seh-rt_v5-rev1\mingw64\bin
|
||||
to your PATH env variable.
|
||||
|
||||
Docs: https://gitea.com/xorm/xorm
|
||||
*/
|
||||
|
||||
// User is our user table structure.
|
||||
type User struct {
|
||||
ID int64 // auto-increment by-default by xorm
|
||||
Version string `xorm:"varchar(200)"`
|
||||
Salt string
|
||||
Username string
|
||||
Password string `xorm:"varchar(200)"`
|
||||
Languages string `xorm:"varchar(200)"`
|
||||
CreatedAt time.Time `xorm:"created"`
|
||||
UpdatedAt time.Time `xorm:"updated"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
orm, err := xorm.NewEngine("sqlite3", "./test.db")
|
||||
if err != nil {
|
||||
app.Logger().Fatalf("orm failed to initialized: %v", err)
|
||||
}
|
||||
iris.RegisterOnInterrupt(func() {
|
||||
orm.Close()
|
||||
})
|
||||
|
||||
if err = orm.Sync2(new(User)); err != nil {
|
||||
app.Logger().Fatalf("orm failed to initialized User table: %v", err)
|
||||
}
|
||||
|
||||
app.Get("/insert", func(ctx iris.Context) {
|
||||
user := &User{Username: "kataras", Salt: "hash---", Password: "hashed", CreatedAt: time.Now(), UpdatedAt: time.Now()}
|
||||
orm.Insert(user)
|
||||
|
||||
ctx.Writef("user inserted: %#v", user)
|
||||
})
|
||||
|
||||
app.Get("/get", func(ctx iris.Context) {
|
||||
user := User{ID: 1}
|
||||
found, err := orm.Get(&user) // fetch user with ID.
|
||||
if err != nil {
|
||||
ctx.StopWithError(iris.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !found {
|
||||
ctx.StopWithText(iris.StatusNotFound, "User with ID: %d not found", user.ID)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Writef("User Found: %#v", user)
|
||||
})
|
||||
|
||||
// http://localhost:8080/insert
|
||||
// http://localhost:8080/get
|
||||
app.Listen(":8080")
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
const addr = "127.0.0.1:8080"
|
||||
|
||||
/*
|
||||
$ go build -ldflags -H=windowsgui -o myapp.exe
|
||||
$ go build -mod=mod -ldflags -H=windowsgui -o myapp.exe
|
||||
$ ./myapp.exe # run the app
|
||||
*/
|
||||
func main() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
const addr = "127.0.0.1:8080"
|
||||
|
||||
/*
|
||||
$ go build -ldflags="-H windowsgui" -o myapp.exe # build for windows
|
||||
$ go build -mod=mod -ldflags="-H windowsgui" -o myapp.exe # build for windows
|
||||
$ ./myapp.exe # run
|
||||
*/
|
||||
func main() {
|
||||
|
||||
@@ -13,7 +13,7 @@ const addr = "127.0.0.1:8080"
|
||||
# http://tdm-gcc.tdragon.net/download
|
||||
#
|
||||
#
|
||||
$ go build -ldflags="-H windowsgui" -o myapp.exe # build for windows
|
||||
$ go build -mod=mod -ldflags="-H windowsgui" -o myapp.exe # build for windows
|
||||
$ ./myapp.exe # run
|
||||
#
|
||||
#
|
||||
|
||||
@@ -15,8 +15,7 @@ import (
|
||||
// 1. Install Redis:
|
||||
// 1.1 Windows: https://github.com/ServiceStack/redis-windows
|
||||
// 1.2 Other: https://redis.io/download
|
||||
// 2. go mod download
|
||||
// 3. go run main.go
|
||||
// 2. Run command: go run -mod=mod main.go
|
||||
//
|
||||
// Tested with redis version 3.0.503.
|
||||
func main() {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// $ go get go.etcd.io/bbolt/...
|
||||
// $ go get github.com/google/uuid
|
||||
// $ cd $GOPATH/src/github.com/kataras/iris/_examples/url-shortener
|
||||
// $ go build
|
||||
// $ go build -mod=mod
|
||||
// $ ./url-shortener
|
||||
package main
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// GOARCH=wasm GOOS=js /home/$yourusername/go1.14/bin/go build -o hello.wasm hello_go114.go
|
||||
// GOARCH=wasm GOOS=js /home/$yourusername/go1.16/bin/go build -mod=mod -o hello.wasm hello_go116.go
|
||||
js.Global().Get("console").Call("log", "Hello Webassembly!")
|
||||
message := fmt.Sprintf("Hello, the current time is: %s", time.Now().String())
|
||||
js.Global().Get("document").Call("getElementById", "hello").Set("innerText", message)
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
)
|
||||
|
||||
/*
|
||||
You need to build the hello.wasm first, download the go1.14 and execute the below command:
|
||||
$ cd client && GOARCH=wasm GOOS=js /home/$yourname/go1.14/bin/go build -o hello.wasm hello_go114.go
|
||||
You need to build the hello.wasm first, download the go1.16 and execute the below command:
|
||||
$ cd client && GOARCH=wasm GOOS=js /home/$yourname/go1.16/bin/go build -mod=mod -o hello.wasm hello_go116.go
|
||||
*/
|
||||
|
||||
func main() {
|
||||
|
||||
Reference in New Issue
Block a user