Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from vidar-team/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
wuhan005 authored Apr 8, 2020
2 parents 1ccb945 + 18b0ff6 commit 8b6c832
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 135 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: compile and release
uses: wuhan005/[email protected]
uses: wuhan005/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GOARCH: "386"
Expand All @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: compile and release
uses: wuhan005/[email protected]
uses: wuhan005/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GOARCH: amd64
Expand All @@ -29,7 +29,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: compile and release
uses: wuhan005/[email protected]
uses: wuhan005/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GOARCH: arm
Expand All @@ -40,7 +40,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: compile and release
uses: wuhan005/[email protected]
uses: wuhan005/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GOARCH: arm64
Expand All @@ -51,7 +51,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: compile and release
uses: wuhan005/[email protected]
uses: wuhan005/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GOARCH: "386"
Expand All @@ -62,7 +62,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: compile and release
uses: wuhan005/[email protected]
uses: wuhan005/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GOARCH: amd64
Expand All @@ -73,7 +73,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: compile and release
uses: wuhan005/[email protected]
uses: wuhan005/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GOARCH: "386"
Expand All @@ -84,7 +84,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: compile and release
uses: wuhan005/[email protected]
uses: wuhan005/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GOARCH: amd64
Expand All @@ -95,7 +95,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: compile and release
uses: wuhan005/[email protected]
uses: wuhan005/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GOARCH: arm
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ TODO

十分欢迎您和我们一起改进 Cardinal,您可以改进现有程序,加入新功能,完善文档,优化代码等。

[![Contributors](http://ergatejs.implements.io/badges/contributors/vidar-team/Cardinal_1280_96_10.png)](https://github.com/vidar-team/Cardinal/graphs/contributors)

## 协议与许可

© Vidar-Team
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/dustin/go-humanize v1.0.0
github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484 // indirect
github.com/gin-contrib/cors v1.3.0
github.com/gin-contrib/static v0.0.0-20191128031702-f81c604d8ac2
github.com/gin-gonic/gin v1.5.0
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/sessions v1.2.0 // indirect
Expand All @@ -34,6 +35,8 @@ require (
github.com/stretchr/testify v1.4.0
github.com/thanhpk/randstr v1.0.4
github.com/theplant/cldr v0.0.0-20190423050709-9f76f7ce4ee8 // indirect
github.com/vidar-team/Cardinal_frontend v0.0.0-20200408105230-89ca4c2e48db
github.com/vidar-team/Cardinal_manager_frontend v0.0.4
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect
golang.org/x/text v0.3.0
Expand Down
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6RO
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484 h1:pEtiCjIXx3RvGjlUJuCNxNOw0MNblyR9Wi+vJGBFh+8=
github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 h1:dWB6v3RcOy03t/bUadywsbyrQwCqZeNIEX6M1OtSZOM=
Expand All @@ -20,6 +21,8 @@ github.com/gin-contrib/cors v1.3.0/go.mod h1:artPvLlhkF7oG06nK8v3U8TNz6IeX+w1uzC
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-contrib/static v0.0.0-20191128031702-f81c604d8ac2 h1:xLG16iua01X7Gzms9045s2Y2niNpvSY/Zb1oBwgNYZY=
github.com/gin-contrib/static v0.0.0-20191128031702-f81c604d8ac2/go.mod h1:VhW/Ch/3FhimwZb8Oj+qJmdMmoB8r7lmJ5auRjm50oQ=
github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=
github.com/gin-gonic/gin v1.5.0 h1:fi+bqFAx/oLK54somfCtEZs9HeH1LHVoEPUgARpTqyc=
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
Expand Down Expand Up @@ -139,6 +142,16 @@ github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/vidar-team/Cardinal_frontend v0.0.0-20200408105230-89ca4c2e48db h1:R9nMC/Zod/SH/lFbohxQs+CYjButnfrj+Vc+3p60QLU=
github.com/vidar-team/Cardinal_frontend v0.0.0-20200408105230-89ca4c2e48db/go.mod h1:wD4qPD/Z+T3eT0SiOQe9262VY6xSyWz12UQXmkH9uiI=
github.com/vidar-team/Cardinal_manager_frontend v0.0.0-20200408130640-9d0e4fd421ed h1:X6rV0vkAZHgaO8KWq081tePy98ioiuTbT1X+1G+WQQo=
github.com/vidar-team/Cardinal_manager_frontend v0.0.0-20200408130640-9d0e4fd421ed/go.mod h1:uJBQtuXHTLNyuIMONoM1OqYmW7Q/N40+587Qt90kqAk=
github.com/vidar-team/Cardinal_manager_frontend v0.0.1 h1:8+uR3BlotRN5go81Xa4Ek+R4G7fDabYjzM9yAWcNgEQ=
github.com/vidar-team/Cardinal_manager_frontend v0.0.1/go.mod h1:uJBQtuXHTLNyuIMONoM1OqYmW7Q/N40+587Qt90kqAk=
github.com/vidar-team/Cardinal_manager_frontend v0.0.2 h1:hzdryqDLhYwwJmXuYuY8vxUA+0HlIDtACo+sREdasKQ=
github.com/vidar-team/Cardinal_manager_frontend v0.0.2/go.mod h1:uJBQtuXHTLNyuIMONoM1OqYmW7Q/N40+587Qt90kqAk=
github.com/vidar-team/Cardinal_manager_frontend v0.0.4 h1:qnuR7CIhkmO9jXc5TppYkCxaLTQsxTG0oK3+wZzlVW0=
github.com/vidar-team/Cardinal_manager_frontend v0.0.4/go.mod h1:uJBQtuXHTLNyuIMONoM1OqYmW7Q/N40+587Qt90kqAk=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd h1:GGJVjV8waZKRHrgwvtH66z9ZGVurTD1MT0n1Bb+q4aM=
Expand Down
18 changes: 9 additions & 9 deletions src/bulletin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestService_GetAllBulletins(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/manager/bulletins", nil)
req, _ := http.NewRequest("GET", "/api/manager/bulletins", nil)
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
Expand All @@ -23,7 +23,7 @@ func TestService_NewBulletin(t *testing.T) {
jsonData, _ := json.Marshal(map[string]interface{}{
"Title": "this is a bulletin",
})
req, _ := http.NewRequest("POST", "/manager/bulletin", bytes.NewBuffer(jsonData))
req, _ := http.NewRequest("POST", "/api/manager/bulletin", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 400, w.Code)
Expand All @@ -34,7 +34,7 @@ func TestService_NewBulletin(t *testing.T) {
"Title": "this is a bulletin",
"Content": "test test test",
})
req, _ = http.NewRequest("POST", "/manager/bulletin", bytes.NewBuffer(jsonData))
req, _ = http.NewRequest("POST", "/api/manager/bulletin", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
Expand All @@ -47,7 +47,7 @@ func TestService_EditBulletin(t *testing.T) {
"Title": "this is a bulletin",
"Content": "new content",
})
req, _ := http.NewRequest("PUT", "/manager/bulletin", bytes.NewBuffer(jsonData))
req, _ := http.NewRequest("PUT", "/api/manager/bulletin", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 400, w.Code)
Expand All @@ -59,7 +59,7 @@ func TestService_EditBulletin(t *testing.T) {
"Title": "this is a bulletin",
"Content": "new content",
})
req, _ = http.NewRequest("PUT", "/manager/bulletin", bytes.NewBuffer(jsonData))
req, _ = http.NewRequest("PUT", "/api/manager/bulletin", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 404, w.Code)
Expand All @@ -71,7 +71,7 @@ func TestService_EditBulletin(t *testing.T) {
"Title": "this is a bulletin",
"Content": "new content",
})
req, _ = http.NewRequest("PUT", "/manager/bulletin", bytes.NewBuffer(jsonData))
req, _ = http.NewRequest("PUT", "/api/manager/bulletin", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
Expand All @@ -80,21 +80,21 @@ func TestService_EditBulletin(t *testing.T) {
func TestService_DeleteBulletin(t *testing.T) {
// error id
w := httptest.NewRecorder()
req, _ := http.NewRequest("DELETE", "/manager/bulletin?id=asdfg", nil)
req, _ := http.NewRequest("DELETE", "/api/manager/bulletin?id=asdfg", nil)
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 400, w.Code)

// id not exist
w = httptest.NewRecorder()
req, _ = http.NewRequest("DELETE", "/manager/bulletin?id=233", nil)
req, _ = http.NewRequest("DELETE", "/api/manager/bulletin?id=233", nil)
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 404, w.Code)

// success
w = httptest.NewRecorder()
req, _ = http.NewRequest("DELETE", "/manager/bulletin?id=1", nil)
req, _ = http.NewRequest("DELETE", "/api/manager/bulletin?id=1", nil)
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
Expand Down
30 changes: 15 additions & 15 deletions src/challenge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestService_NewChallenge(t *testing.T) {
jsonData, _ := json.Marshal(map[string]interface{}{
"Title": "Web1",
})
req, _ := http.NewRequest("POST", "/manager/challenge", bytes.NewBuffer(jsonData))
req, _ := http.NewRequest("POST", "/api/manager/challenge", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 400, w.Code)
Expand All @@ -26,7 +26,7 @@ func TestService_NewChallenge(t *testing.T) {
"Title": "Web1",
"BaseScore": 800,
})
req, _ = http.NewRequest("POST", "/manager/challenge", bytes.NewBuffer(jsonData))
req, _ = http.NewRequest("POST", "/api/manager/challenge", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
Expand All @@ -36,7 +36,7 @@ func TestService_NewChallenge(t *testing.T) {
"Title": "Pwn2",
"BaseScore": 1000,
})
req, _ = http.NewRequest("POST", "/manager/challenge", bytes.NewBuffer(jsonData))
req, _ = http.NewRequest("POST", "/api/manager/challenge", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
Expand All @@ -46,7 +46,7 @@ func TestService_NewChallenge(t *testing.T) {
"Title": "Pwn1",
"BaseScore": 1000,
})
req, _ = http.NewRequest("POST", "/manager/challenge", bytes.NewBuffer(jsonData))
req, _ = http.NewRequest("POST", "/api/manager/challenge", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
Expand All @@ -57,7 +57,7 @@ func TestService_NewChallenge(t *testing.T) {
"Title": "Web1",
"BaseScore": 800,
})
req, _ = http.NewRequest("POST", "/manager/challenge", bytes.NewBuffer(jsonData))
req, _ = http.NewRequest("POST", "/api/manager/challenge", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 403, w.Code)
Expand All @@ -70,7 +70,7 @@ func TestService_EditChallenge(t *testing.T) {
"Title": "Web1",
"BaseScore": 1000,
})
req, _ := http.NewRequest("PUT", "/manager/challenge", bytes.NewBuffer(jsonData))
req, _ := http.NewRequest("PUT", "/api/manager/challenge", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 400, w.Code)
Expand All @@ -82,7 +82,7 @@ func TestService_EditChallenge(t *testing.T) {
"Title": "Web1",
"BaseScore": 1000,
})
req, _ = http.NewRequest("PUT", "/manager/challenge", bytes.NewBuffer(jsonData))
req, _ = http.NewRequest("PUT", "/api/manager/challenge", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 404, w.Code)
Expand All @@ -94,7 +94,7 @@ func TestService_EditChallenge(t *testing.T) {
"Title": "Web233",
"BaseScore": 800,
})
req, _ = http.NewRequest("PUT", "/manager/challenge", bytes.NewBuffer(jsonData))
req, _ = http.NewRequest("PUT", "/api/manager/challenge", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
Expand All @@ -105,15 +105,15 @@ func TestService_EditChallenge(t *testing.T) {
"Title": "Web1",
"BaseScore": 1000,
})
req, _ = http.NewRequest("PUT", "/manager/challenge", bytes.NewBuffer(jsonData))
req, _ = http.NewRequest("PUT", "/api/manager/challenge", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
}

func TestService_GetAllChallenges(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/manager/challenges", nil)
req, _ := http.NewRequest("GET", "/api/manager/challenges", nil)
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
Expand All @@ -122,21 +122,21 @@ func TestService_GetAllChallenges(t *testing.T) {
func TestService_DeleteChallenge(t *testing.T) {
// error id
w := httptest.NewRecorder()
req, _ := http.NewRequest("DELETE", "/manager/challenge?id=asdfg", nil)
req, _ := http.NewRequest("DELETE", "/api/manager/challenge?id=asdfg", nil)
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 400, w.Code)

// id not exist
w = httptest.NewRecorder()
req, _ = http.NewRequest("DELETE", "/manager/challenge?id=233", nil)
req, _ = http.NewRequest("DELETE", "/api/manager/challenge?id=233", nil)
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 404, w.Code)

// success delete 2
w = httptest.NewRecorder()
req, _ = http.NewRequest("DELETE", "/manager/challenge?id=2", nil)
req, _ = http.NewRequest("DELETE", "/api/manager/challenge?id=2", nil)
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
Expand All @@ -149,7 +149,7 @@ func TestService_SetVisible(t *testing.T) {
"ID": 1,
"Visible": "true",
})
req, _ := http.NewRequest("POST", "/manager/challenge/visible", bytes.NewBuffer(jsonData))
req, _ := http.NewRequest("POST", "/api/manager/challenge/visible", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 400, w.Code)
Expand All @@ -160,7 +160,7 @@ func TestService_SetVisible(t *testing.T) {
"ID": 2,
"Visible": true,
})
req, _ = http.NewRequest("POST", "/manager/challenge/visible", bytes.NewBuffer(jsonData))
req, _ = http.NewRequest("POST", "/api/manager/challenge/visible", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", managerToken)
service.Router.ServeHTTP(w, req)
assert.Equal(t, 404, w.Code)
Expand Down
43 changes: 43 additions & 0 deletions src/fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
frontend "github.com/vidar-team/Cardinal_frontend/dist"
manager "github.com/vidar-team/Cardinal_manager_frontend/dist"
"net/http"
"strings"
)

// FrontendFS is the file system struct of challengers' frontend.
type FrontendFS struct {
frontendFS http.FileSystem
managerFS http.FileSystem
}

func frontendFS() *FrontendFS {
return &FrontendFS{
frontendFS: frontend.New(),
managerFS: manager.New(),
}
}

// Open: open file.
func (f *FrontendFS) Open(name string) (http.File, error) {
if strings.HasPrefix(name, "/manager") {
return f.managerFS.Open(name)
}
return f.frontendFS.Open(name)
}

// Exists: check if the file exist.
func (f *FrontendFS) Exists(prefix string, filePath string) bool {
if strings.HasPrefix(filePath, "/manager") {
if _, err := f.managerFS.Open(filePath); err != nil {
return false
}
return true
}
if _, err := f.frontendFS.Open(filePath); err != nil {
return false
}
return true
}
Loading

0 comments on commit 8b6c832

Please sign in to comment.