Skip to content

Commit 39d2986

Browse files
committed
init
0 parents  commit 39d2986

24 files changed

+1615
-0
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, build with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
.DS_Store
14+
main
15+
leetcode-badge
16+
nginx/
17+
docker-compose.yml
18+
static/*.go

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ARG GO_VERSION=1.12.7
2+
3+
FROM golang:${GO_VERSION}-alpine3.9 AS build-env
4+
5+
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
6+
7+
RUN apk --no-cache add build-base git
8+
9+
WORKDIR ${GOPATH}/src/github.com/haozibi/leetcode-badge
10+
11+
COPY . ${GOPATH}/src/github.com/haozibi/leetcode-badge
12+
13+
RUN ls -alh && make build-linux
14+
15+
FROM alpine:3.9
16+
17+
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
18+
19+
RUN apk update && apk add tzdata \
20+
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
21+
&& echo "Asia/Shanghai" > /etc/timezone
22+
23+
RUN apk add --update ca-certificates && rm -rf /var/cache/apk/*
24+
25+
COPY --from=build-env go/src/github.com/haozibi/leetcode-badge/leetcode-badge /main
26+
27+
ENV LCHTTPAddr=":5050"
28+
29+
EXPOSE 5050
30+
31+
ENTRYPOINT ["/main","run"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 haozibi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
APP?=leetcode-badge
2+
3+
# SHELL := /bin/bash # Use bash syntax
4+
GOOS?=linux
5+
GOARCH?=amd64
6+
7+
VERSION?=$(shell git describe --tags --always)
8+
NOW?=$(shell date -u '+%Y/%m/%d/%I:%M:%S%Z')
9+
PROJECT?=github.com/haozibi/${APP}
10+
11+
LDFLAGS += -X "${PROJECT}/app.BuildTime=${NOW}"
12+
LDFLAGS += -X "${PROJECT}/app.BuildVersion=${VERSION}"
13+
LDFLAGS += -X "${PROJECT}/app.BuildAppName=${APP}"
14+
BUILD_TAGS = ""
15+
BUILD_FLAGS = "-v"
16+
# PROTO_LOCATION = "internal/protocol_pb"
17+
18+
.PHONY: build build-local build-linux clean govet bindata docker-image
19+
20+
default: build
21+
22+
build: clean bindata govet
23+
CGO_ENABLED=0 GOOS= GOARCH= go build ${BUILD_FLAGS} -ldflags '${LDFLAGS}' -tags '${BUILD_TAGS}' -o ${APP}
24+
25+
26+
build-linux: clean bindata govet
27+
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build ${BUILD_FLAGS} -ldflags '${LDFLAGS}' -tags '${BUILD_TAGS}' -o ${APP}
28+
29+
bindata:
30+
go get github.com/jteeuwen/go-bindata/...
31+
go-bindata -nomemcopy -pkg=static \
32+
-debug=false \
33+
-o=static/static.go \
34+
static/...
35+
36+
govet:
37+
@ go vet . && go fmt ./... && \
38+
(if [[ "$(gofmt -d $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./tests/*" -not -path "./assets/*"))" == "" ]]; then echo "Good format"; else echo "Bad format"; exit 33; fi);
39+
40+
clean:
41+
@ rm -fr ${APP} main static/*.go
42+

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
![](static/logo.png)
2+
3+
[![](https://img.shields.io/badge/Github-leetcode--badge-blueviolet)](https://github.com/haozibi/leetcode-badge) [![](https://lc.coding.gs/v1cn/haozibi.svg)](https://leetcode-cn.com/haozibi) [![](https://lc.coding.gs/v1cn/ranking/haozibi.svg)](https://leetcode-cn.com/haozibi) [![](https://lc.coding.gs/v1cn/solved/haozibi.svg)](https://leetcode-cn.com/haozibi) [![](https://lc.coding.gs/v1cn/solved-rate/haozibi.svg)](https://leetcode-cn.com/haozibi) [![](https://lc.coding.gs/v1cn/accepted/haozibi.svg)](https://leetcode-cn.com/haozibi) [![](https://lc.coding.gs/v1cn/accepted-rate/haozibi.svg)](https://leetcode-cn.com/haozibi)
4+
5+
# leetcode 徽标
6+
7+
<!-- TOC -->
8+
9+
- [leetcode 徽标](#leetcode-徽标)
10+
- [使用](#使用)
11+
- [用户名](#用户名)
12+
- [排名](#排名)
13+
- [通过题目数/总题目数](#通过题目数总题目数)
14+
- [通过题目数/总题目数 比例](#通过题目数总题目数-比例)
15+
- [通过提交/总提交](#通过提交总提交)
16+
- [通过提交/总提交 比例](#通过提交总提交-比例)
17+
- [自定义](#自定义)
18+
- [致谢](#致谢)
19+
20+
<!-- /TOC -->
21+
22+
23+
## 使用
24+
25+
*数据 15 分钟更新一次*[https://leetcode.com/haozibi](https://leetcode.com/haozibi)`{LeetCode_ID}`*haozibi*
26+
27+
### 用户名
28+
29+
- ![](https://lc.coding.gs/v1cn/haozibi.svg)
30+
- LeetCode: `https://lc.coding.gs/v1/{LeetCode_ID}.svg`
31+
- LeetCodeCN: `https://lc.coding.gs/v1cn/{LeetCode_ID}.svg`
32+
33+
### 排名
34+
35+
- ![](https://lc.coding.gs/v1cn/ranking/haozibi.svg)
36+
- LeetCode: `https://lc.coding.gs/v1/ranking/{LeetCode_ID}.svg`
37+
- LeetCodeCN: `https://lc.coding.gs/v1cn/ranking/{LeetCode_ID}.svg`
38+
39+
40+
### 通过题目数/总题目数
41+
42+
- ![](https://lc.coding.gs/v1cn/solved/haozibi.svg)
43+
- LeetCode: `https://lc.coding.gs/v1/solved/{LeetCode_ID}.svg`
44+
- LeetCodeCN: `https://lc.coding.gs/v1cn/solved/{LeetCode_ID}.svg`
45+
46+
### 通过题目数/总题目数 比例
47+
48+
- ![](https://lc.coding.gs/v1cn/solved-rate/haozibi.svg)
49+
- LeetCode: `https://lc.coding.gs/v1/solved-rate/{LeetCode_ID}.svg`
50+
- LeetCodeCN: `https://lc.coding.gs/v1cn/solved-rate/{LeetCode_ID}.svg`
51+
52+
### 通过提交/总提交
53+
54+
- ![](https://lc.coding.gs/v1cn/accepted/haozibi.svg)
55+
- LeetCode: `https://lc.coding.gs/v1/accepted/{LeetCode_ID}.svg`
56+
- LeetCodeCN: `https://lc.coding.gs/v1cn/accepted/{LeetCode_ID}.svg`
57+
58+
### 通过提交/总提交 比例
59+
60+
- ![](https://lc.coding.gs/v1cn/accepted-rate/haozibi.svg)
61+
- LeetCode: `https://lc.coding.gs/v1/accepted-rate/{LeetCode_ID}.svg`
62+
- LeetCodeCN: `https://lc.coding.gs/v1cn/accepted-rate/{LeetCode_ID}.svg`
63+
64+
## 自定义
65+
66+
此项目依托 [shields.io](shields.io),支持所有 shields 的 Query 参数
67+
68+
例如:
69+
70+
- ![](https://lc.coding.gs/v1cn/ranking/haozibi.svg?logo=leetcode) `https://lc.coding.gs/v1cn/ranking/haozibi.svg?logo=leetcode`
71+
- ![](https://lc.coding.gs/v1cn/ranking/haozibi.svg?color=ff5983&logo=leetcode) `https://lc.coding.gs/v1cn/ranking/haozibi.svg?color=ff5983&logo=leetcode`
72+
- ![](https://lc.coding.gs/v1cn/ranking/haozibi.svg?style=for-the-badge&color=ff5983&logo=leetcode) `https://lc.coding.gs/v1cn/ranking/haozibi.svg?style=for-the-badge&color=ff5983&logo=leetcode`
73+
74+
## 致谢
75+
76+
- [Picas](https://github.com/djyde/Picas):logo 生成
77+
- [shields.io](https://shields.io): badge 生成

app/app.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package app
2+
3+
import (
4+
"io/ioutil"
5+
"net/http"
6+
"os"
7+
8+
"github.com/haozibi/leetcode-badge/internal/cache"
9+
"github.com/haozibi/leetcode-badge/internal/cache/memory"
10+
"github.com/haozibi/leetcode-badge/internal/cache/redis"
11+
12+
"github.com/gorilla/mux"
13+
"github.com/haozibi/zlog"
14+
)
15+
16+
type APP struct {
17+
debug bool
18+
config *Config
19+
cache cache.Cache
20+
err error
21+
}
22+
23+
func New(c *Config) *APP {
24+
25+
a := new(APP)
26+
a.config = c
27+
a.debug = c.Debug
28+
29+
if a.debug {
30+
zlog.NewBasicLog(os.Stderr, zlog.WithDebug(true))
31+
}
32+
33+
switch c.CacheType {
34+
case cache.CacheRedis:
35+
a.cache, a.err = redis.New(c.CacheAddr, c.CachePasswd)
36+
case cache.CacheMemory:
37+
a.cache = memory.New()
38+
}
39+
40+
return a
41+
}
42+
43+
func (a *APP) Run() error {
44+
45+
if a.err != nil {
46+
return a.err
47+
}
48+
49+
r := mux.NewRouter()
50+
51+
setRouter(r, a, ioutil.Discard)
52+
53+
zlog.ZInfo().Str("Addr", a.config.ListenAddr).Msg("[http]")
54+
if err := http.ListenAndServe(a.config.ListenAddr, r); err != nil {
55+
return err
56+
}
57+
58+
return nil
59+
}
60+
61+
type Config struct {
62+
CacheType cache.CacheType
63+
CacheAddr string
64+
CachePasswd string
65+
ListenAddr string
66+
Debug bool
67+
}

0 commit comments

Comments
 (0)