Skip to content

Commit 3176fa4

Browse files
committed
feat(add init commit): add init commit
add init commit BREAKING CHANGE: add init commit
0 parents  commit 3176fa4

File tree

23 files changed

+809
-0
lines changed

23 files changed

+809
-0
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.env
2+
*.png
3+
*.svg
4+
docker-compose.yml
5+
Dockerfile
6+
README.md

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
go.work.sum
23+
24+
# env file
25+
.env
26+
bin

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM golang:1.22.4 AS base
2+
WORKDIR /app
3+
ADD . /app/
4+
RUN go mod download
5+
RUN make build
6+
FROM alpine AS release
7+
WORKDIR /app
8+
COPY --from=base /app/bin/main /app/
9+
ENTRYPOINT [ "./main" ]

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.PHONY=build
2+
3+
build:
4+
@CGO_ENABLED=0 GOOS=linux go build -o bin/main cmd/main.go
5+
6+
run: build
7+
@./bin/main
8+

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# golang-memcache-sample
2+
3+
This project is to demo how to use memcache to lower latency while data are existed with golang
4+
5+
## architecture
6+
7+
8+
![architecture](architecture.png)
9+
## package dependency
10+
11+
1. fiber
12+
```shell
13+
go get github.com/gofiber/fiber/v2
14+
```
15+
2. memcache
16+
```shell
17+
go get github.com/bradfitz/gomemcache/memcache
18+
```
19+
20+
## dependency diagram
21+
22+
```shell=
23+
goda graph github.com/leetcode-golang-classroom/golang-memcache-sample/... | dot -Tsvg -o dependency-graph.svg
24+
```
25+
26+
![dependency-graph](./dependency-graph.svg)
27+
28+
## injection relation
29+
30+
![injection-relation.png](./injection-relation.png)
31+
32+
## docker compose run
33+
34+
```shell
35+
docker compose up -d
36+
```

architecture.png

425 KB
Loading

cmd/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log"
6+
"os"
7+
"os/signal"
8+
"syscall"
9+
10+
"github.com/leetcode-golang-classroom/golang-memcache-sample/internal/application"
11+
"github.com/leetcode-golang-classroom/golang-memcache-sample/internal/config"
12+
)
13+
14+
func main() {
15+
app := application.New(config.AppConfig)
16+
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
17+
defer cancel()
18+
err := app.Start(ctx)
19+
if err != nil {
20+
log.Fatalf("failed to start stock server:%v", err)
21+
}
22+
}

dependency-graph.svg

Lines changed: 137 additions & 0 deletions
Loading

docker-compose.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
networks:
2+
memcached:
3+
name: memcached
4+
driver: bridge
5+
6+
services:
7+
memcached:
8+
image: memcached:alpine
9+
container_name: memcached
10+
ports:
11+
- 11211:11211
12+
entrypoint: ["memcached", "-m", "64"]
13+
restart: always
14+
networks:
15+
- memcached
16+
healthcheck:
17+
test: echo stats | nc 127.0.0.1 11211
18+
interval: 10s
19+
retries: 60
20+
photos-api:
21+
build:
22+
context: .
23+
dockerfile: ./Dockerfile
24+
container_name: photos-api
25+
depends_on:
26+
memcached:
27+
condition: service_healthy
28+
environment:
29+
PORT: 4000
30+
MEMCACHE_URL: memcached:11211
31+
JSONSERVER_URL: https://jsonplaceholder.typicode.com/photos
32+
ports:
33+
- 4000:4000
34+
networks:
35+
- memcached

go.mod

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module github.com/leetcode-golang-classroom/golang-memcache-sample
2+
3+
go 1.22.4
4+
5+
require (
6+
github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874
7+
github.com/gofiber/fiber/v2 v2.52.5
8+
github.com/spf13/viper v1.19.0
9+
)
10+
11+
require (
12+
github.com/andybalholm/brotli v1.0.5 // indirect
13+
github.com/fsnotify/fsnotify v1.7.0 // indirect
14+
github.com/google/uuid v1.5.0 // indirect
15+
github.com/hashicorp/hcl v1.0.0 // indirect
16+
github.com/klauspost/compress v1.17.2 // indirect
17+
github.com/magiconair/properties v1.8.7 // indirect
18+
github.com/mattn/go-colorable v0.1.13 // indirect
19+
github.com/mattn/go-isatty v0.0.20 // indirect
20+
github.com/mattn/go-runewidth v0.0.15 // indirect
21+
github.com/mitchellh/mapstructure v1.5.0 // indirect
22+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
23+
github.com/rivo/uniseg v0.2.0 // indirect
24+
github.com/sagikazarmark/locafero v0.4.0 // indirect
25+
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
26+
github.com/sourcegraph/conc v0.3.0 // indirect
27+
github.com/spf13/afero v1.11.0 // indirect
28+
github.com/spf13/cast v1.6.0 // indirect
29+
github.com/spf13/pflag v1.0.5 // indirect
30+
github.com/subosito/gotenv v1.6.0 // indirect
31+
github.com/valyala/bytebufferpool v1.0.0 // indirect
32+
github.com/valyala/fasthttp v1.51.0 // indirect
33+
github.com/valyala/tcplisten v1.0.0 // indirect
34+
go.uber.org/atomic v1.9.0 // indirect
35+
go.uber.org/multierr v1.9.0 // indirect
36+
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
37+
golang.org/x/sys v0.18.0 // indirect
38+
golang.org/x/text v0.14.0 // indirect
39+
gopkg.in/ini.v1 v1.67.0 // indirect
40+
gopkg.in/yaml.v3 v3.0.1 // indirect
41+
)

0 commit comments

Comments
 (0)