Commit 32dda7f8 authored by Konrad Borowski's avatar Konrad Borowski

Add Go language

parent 3db7e82e
Pipeline #98152877 passed with stages
in 16 minutes and 2 seconds
...@@ -6,6 +6,7 @@ const languagesMap = { ...@@ -6,6 +6,7 @@ const languagesMap = {
c: [() => import('codemirror/mode/clike/clike'), 'text/x-csrc'], c: [() => import('codemirror/mode/clike/clike'), 'text/x-csrc'],
cpp: [() => import('codemirror/mode/clike/clike'), 'text/x-c++src'], cpp: [() => import('codemirror/mode/clike/clike'), 'text/x-c++src'],
csharp: [() => import('codemirror/mode/clike/clike'), 'text/x-csharp'], csharp: [() => import('codemirror/mode/clike/clike'), 'text/x-csharp'],
go: [() => import('codemirror/mode/go/go'), 'text/x-go'],
haskell: [() => import('codemirror/mode/haskell/haskell'), 'text/x-haskell'], haskell: [() => import('codemirror/mode/haskell/haskell'), 'text/x-haskell'],
html: [() => import('codemirror/mode/htmlmixed/htmlmixed'), 'text/html'], html: [() => import('codemirror/mode/htmlmixed/htmlmixed'), 'text/html'],
java: [() => import('codemirror/mode/clike/clike'), 'text/x-java'], java: [() => import('codemirror/mode/clike/clike'), 'text/x-java'],
......
...@@ -29,6 +29,7 @@ const languageMap = { ...@@ -29,6 +29,7 @@ const languageMap = {
c: 'objective-c', // Somehow the repo doesn't have C language c: 'objective-c', // Somehow the repo doesn't have C language
cpp: 'cpp', cpp: 'cpp',
csharp: 'csharp', csharp: 'csharp',
go: 'go',
haskell: null, haskell: null,
html: 'html', html: 'html',
java: 'java', java: 'java',
......
...@@ -79,6 +79,30 @@ ...@@ -79,6 +79,30 @@
} }
] ]
}, },
{
"identifier": "go",
"name": "Go",
"helloworld": "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello, world!\")\n}",
"implementations": [
{
"label": "gc",
"identifier": "gc",
"wrappers": [
{
"identifier": "gc",
"label": "Run",
"code": "mv code code.go; go run code.go"
},
{
"identifier": "goimports",
"label": "Format",
"code": "goimports -w code; cat code",
"is_formatter": true
}
]
}
]
},
{ {
"identifier": "haskell", "identifier": "haskell",
"name": "Haskell", "name": "Haskell",
......
ALTER TABLE languages DROP CONSTRAINT languages_identifier_key;
CREATE INDEX ON languages (identifier);
DROP INDEX languages_identifier_idx;
ALTER TABLE languages ADD CONSTRAINT languages_identifier_key UNIQUE (identifier);
...@@ -8,13 +8,21 @@ use std::error::Error; ...@@ -8,13 +8,21 @@ use std::error::Error;
use std::fs; use std::fs;
#[derive(Deserialize)] #[derive(Deserialize)]
struct Language { struct JsonLanguage {
identifier: String, identifier: String,
name: String,
helloworld: Option<String>, helloworld: Option<String>,
#[serde(default)] #[serde(default)]
implementations: Vec<Implementation>, implementations: Vec<Implementation>,
} }
#[derive(Insertable)]
struct Language<'a> {
identifier: &'a str,
name: String,
priority: i32,
}
#[derive(Deserialize)] #[derive(Deserialize)]
struct Implementation { struct Implementation {
label: String, label: String,
...@@ -35,13 +43,23 @@ struct Wrapper { ...@@ -35,13 +43,23 @@ struct Wrapper {
} }
pub fn run(connection: &Connection) -> Result<(), Box<dyn Error>> { pub fn run(connection: &Connection) -> Result<(), Box<dyn Error>> {
let languages: Vec<Language> = serde_json::from_slice(&fs::read("languages.json")?)?; let languages: Vec<JsonLanguage> = serde_json::from_slice(&fs::read("languages.json")?)?;
for Language { for JsonLanguage {
identifier: languages_identifier, identifier: languages_identifier,
name,
helloworld, helloworld,
implementations, implementations,
} in languages } in languages
{ {
diesel::insert_into(languages::table)
.values(Language {
identifier: &languages_identifier,
name,
priority: 10,
})
.on_conflict(languages::identifier)
.do_nothing()
.execute(connection)?;
if let Some(hello_world) = helloworld { if let Some(hello_world) = helloworld {
let paste_id: Option<i32> = languages::table let paste_id: Option<i32> = languages::table
.filter(languages::identifier.eq(&languages_identifier)) .filter(languages::identifier.eq(&languages_identifier))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment