-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
FROM golang:1.22.5-alpine3.20 AS build-dev | ||
|
||
WORKDIR /go/src/app | ||
|
||
COPY . . | ||
|
||
RUN go env -w GO111MODULE=on && \ | ||
go env -w GOPROXY=https://goproxy.cn,direct && \ | ||
go mod download && \ | ||
apk add --no-cache upx && \ | ||
go build -trimpath -ldflags="-s -w" -o holiday . && \ | ||
[ -e /usr/bin/upx ] && upx holiday || echo | ||
|
||
FROM alpine | ||
|
||
RUN apk update && \ | ||
apk add --no-cache tzdata | ||
|
||
ENV TZ=Asia/Shanghai | ||
|
||
COPY --from=build-dev /go/src/app/holiday ./holiday | ||
|
||
EXPOSE 80 | ||
|
||
CMD ["./holiday"] | ||
FROM golang:1.22.5-alpine3.20 AS build-dev | ||
|
||
WORKDIR /go/src/app | ||
|
||
COPY . . | ||
|
||
RUN go env -w GO111MODULE=on && \ | ||
go env -w GOPROXY=https://goproxy.cn,direct && \ | ||
go mod download && \ | ||
apk add --no-cache upx && \ | ||
go build -trimpath -ldflags="-s -w" -o holiday . && \ | ||
[ -e /usr/bin/upx ] && upx holiday || echo | ||
|
||
FROM alpine | ||
|
||
RUN apk update && \ | ||
apk add --no-cache tzdata | ||
|
||
ENV TZ=Asia/Shanghai | ||
ENV HOLIDAY_PORT=80 | ||
|
||
COPY --from=build-dev /go/src/app/holiday ./holiday | ||
|
||
EXPOSE $HOLIDAY_PORT | ||
|
||
CMD ["./holiday"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/kelseyhightower/envconfig" | ||
"github.com/xiaoxuan6/chinese-holidays-api/router" | ||
"log" | ||
"net/http" | ||
"strconv" | ||
) | ||
|
||
type env struct { | ||
PORT int | ||
} | ||
|
||
var e env | ||
|
||
func init() { | ||
if err := envconfig.Process("holiday", &e); err != nil { | ||
log.Println("envconfig load fail:", err.Error()) | ||
} | ||
|
||
if e.PORT == 0 { | ||
e.PORT = 80 | ||
} | ||
} | ||
|
||
func main() { | ||
r := router.InitRouter() | ||
log.Panic(http.ListenAndServe(":80", r)) | ||
|
||
port := strconv.Itoa(e.PORT) | ||
log.Println("已启动服务:127.0.0.1:" + port) | ||
if err := http.ListenAndServe(":"+port, r); err != nil { | ||
log.Panic(err) | ||
} | ||
} |