mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 02:47:04 +00:00
update some examples
Former-commit-id: 2ed7c323dd379eb68d5ccb2044cd9cc772ce0b08
This commit is contained in:
3
_examples/tutorial/docker/.dockerignore
Normal file
3
_examples/tutorial/docker/.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
||||
.git
|
||||
node_modules
|
||||
bin
|
||||
17
_examples/tutorial/docker/Dockerfile
Normal file
17
_examples/tutorial/docker/Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
||||
# docker build -t myapp .
|
||||
# docker run --rm -it -p 8080:8080 myapp:latest
|
||||
FROM golang:latest AS builder
|
||||
RUN apt-get update
|
||||
ENV GO111MODULE=on \
|
||||
CGO_ENABLED=0 \
|
||||
GOOS=linux \
|
||||
GOARCH=amd64
|
||||
WORKDIR /go/src/app
|
||||
COPY go.mod .
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN go install
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /go/bin/app .
|
||||
ENTRYPOINT ["./app"]
|
||||
27
_examples/tutorial/docker/README.md
Normal file
27
_examples/tutorial/docker/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Docker Example
|
||||
|
||||
The only requirement for this example is [Docker](https://docs.docker.com/install/).
|
||||
|
||||
## Docker Compose
|
||||
|
||||
The Docker Compose is pre-installed with Docker for Windows. For linux please follow the steps described at: https://docs.docker.com/compose/install/.
|
||||
|
||||
Build and run the application for linux arch and expose it on http://localhost:8080.
|
||||
|
||||
```sh
|
||||
$ docker-compose up
|
||||
```
|
||||
|
||||
See [docker-compose file](docker-compose.yml).
|
||||
|
||||
## Without Docker Compose
|
||||
|
||||
1. Build the image as "myapp" (docker build)
|
||||
2. Run the image and map exposed ports (-p 8080:8080)
|
||||
3. Attach the interactive mode so CTRL/CMD+C signals are respected to shutdown the Iris Server (-it)
|
||||
4. Cleanup the image on finish (--rm)
|
||||
|
||||
```sh
|
||||
$ docker build -t myapp .
|
||||
$ docker run --rm -it -p 8080:8080 myapp:latest
|
||||
```
|
||||
8
_examples/tutorial/docker/docker-compose.yml
Normal file
8
_examples/tutorial/docker/docker-compose.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
# docker-compose up [--build]
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
ports:
|
||||
- 8080:8080
|
||||
7
_examples/tutorial/docker/go.mod
Normal file
7
_examples/tutorial/docker/go.mod
Normal file
@@ -0,0 +1,7 @@
|
||||
module app
|
||||
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/kataras/iris/v12 v12.2.0
|
||||
)
|
||||
26
_examples/tutorial/docker/main.go
Normal file
26
_examples/tutorial/docker/main.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
)
|
||||
|
||||
var addr = flag.String("addr", ":8080", "host:port to listen on")
|
||||
|
||||
// $ docker-compose up
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.HTML("<strong>Hello World!</strong>")
|
||||
})
|
||||
|
||||
app.Get("/api/values/{id:uint}", func(ctx iris.Context) {
|
||||
ctx.Writef("id: %d", ctx.Params().GetUintDefault("id", 0))
|
||||
})
|
||||
|
||||
app.Listen(*addr)
|
||||
}
|
||||
Reference in New Issue
Block a user