-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support judge request with judger v1 api (#17)
- Loading branch information
Showing
10 changed files
with
160 additions
and
23 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,13 +1,13 @@ | ||
{ | ||
"recommendations": [ | ||
"golang.go", | ||
// I don't like this extension for it requires purechase for pro, | ||
// need to find another elegant way for operating & debug with redis | ||
// "cweijan.vscode-redis-client", | ||
"ms-azuretools.vscode-docker", | ||
"ms-vscode.makefile-tools", | ||
"tamasfe.even-better-toml", | ||
"pkief.material-icon-theme", | ||
"ckolkman.vscode-postgres" | ||
], | ||
} | ||
"recommendations": [ | ||
"golang.go", | ||
// I don't like this extension for it requires purechase for pro, | ||
// need to find another elegant way for operating & debug with redis | ||
// "cweijan.vscode-redis-client", | ||
"ms-azuretools.vscode-docker", | ||
"ms-vscode.makefile-tools", | ||
"tamasfe.even-better-toml", | ||
"pkief.material-icon-theme", | ||
"ckolkman.vscode-postgres" | ||
] | ||
} |
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,8 +1,9 @@ | ||
{ | ||
"material-icon-theme.folders.associations": { | ||
"application": "core", | ||
"mapper": "database", | ||
"migration": "import", | ||
"user-service": "server", | ||
} | ||
} | ||
"material-icon-theme.folders.associations": { | ||
"application": "core", | ||
"mapper": "database", | ||
"migration": "import", | ||
"user-service": "server", | ||
"postman": "api" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"id": "5fdf6ce1-e53b-44eb-b273-b44be3db8bab", | ||
"name": "OJ Lab Environment", | ||
"values": [ | ||
{ | ||
"key": "Judger Host", | ||
"value": "localhost:8000", | ||
"type": "default", | ||
"enabled": true | ||
}, | ||
{ | ||
"key": "Service Host", | ||
"value": "localhost:8080", | ||
"type": "default", | ||
"enabled": true | ||
} | ||
], | ||
"_postman_variable_scope": "environment", | ||
"_postman_exported_at": "2023-09-03T02:21:12.497Z", | ||
"_postman_exported_using": "Postman/10.17.4" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "2625a326-8284-4665-b0fc-16199486095d", | ||
"name": "OJ Lab Services", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", | ||
"_exporter_id": "12985580" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "localhost:8000/api/v1/judge/hello-world Copy", | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\r\n \"src\": \"#include <iostream>\\n\\nusing namespace std;\\n\\nint main() {\\n string s;\\n cin >> s;\\n cout << \\\"Hello! \\\" << s << endl;\\n}\\n\",\r\n \"src_language\": \"Cpp\"\r\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "{{Service Host}}/api/v1/problem/hello-world/judge", | ||
"host": [ | ||
"{{Service Host}}" | ||
], | ||
"path": [ | ||
"api", | ||
"v1", | ||
"problem", | ||
"hello-world", | ||
"judge" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package problem | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/OJ-lab/oj-lab-services/packages/application" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
const JUDGER_HOST_PROP = "judger.host" | ||
const JUDGER_JUDGE_PATH = "/api/v1/judge" | ||
|
||
var judgerHost string | ||
|
||
func init() { | ||
judgerHost = application.AppConfig.GetString(JUDGER_HOST_PROP) | ||
} | ||
|
||
type JudgeRequest struct { | ||
Src string `json:"src"` | ||
SrcLanguage string `json:"src_language"` | ||
} | ||
|
||
func Judge(ctx *gin.Context) { | ||
packageSlug := ctx.Param("slug") | ||
|
||
judgeRequest := JudgeRequest{} | ||
if err := ctx.ShouldBindJSON(&judgeRequest); err != nil { | ||
ctx.Error(err) | ||
return | ||
} | ||
|
||
url, err := url.JoinPath(judgerHost, JUDGER_JUDGE_PATH, packageSlug) | ||
if err != nil { | ||
ctx.Error(err) | ||
return | ||
} | ||
payloadBytes, err := json.Marshal(judgeRequest) | ||
if err != nil { | ||
ctx.Error(err) | ||
return | ||
} | ||
client := &http.Client{} | ||
innerRequest, err := http.NewRequest("POST", url, bytes.NewReader(payloadBytes)) | ||
if err != nil { | ||
ctx.Error(err) | ||
return | ||
} | ||
innerRequest.Header.Set("Content-Type", "application/json") | ||
innerRequest.Header.Set("Accept", "application/json") | ||
innerResponse, err := client.Do(innerRequest) | ||
if err != nil { | ||
ctx.Error(err) | ||
return | ||
} | ||
defer innerResponse.Body.Close() | ||
|
||
innerBody := []map[string]interface{}{} | ||
if err := json.NewDecoder(innerResponse.Body).Decode(&innerBody); err != nil { | ||
ctx.Error(err) | ||
return | ||
} | ||
|
||
ctx.JSON(innerResponse.StatusCode, innerBody) | ||
} |
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