Skip to content

Commit 19d6b12

Browse files
Update docs
1 parent df6542c commit 19d6b12

File tree

5 files changed

+178
-32
lines changed

5 files changed

+178
-32
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ A simple wrapper for the WandBox API, written in Golang!
2424

2525
Documentation can be found at [classpythonaddike.github.io/gowandbox/](https://classpythonaddike.github.io/gowandbox/#/)
2626

27-
**Note**: This wrapper supports most of the WandBox API's endpoints, except for the `POST /permlink`. This was because, I couldn't figure out how to work with the endpoint - I kept winding up with `500 - Internal Server Errors`. I'm not sure whether it was a bug in the test data that I was using, or if its a bug in the API itself. Either way, that endpoint has not been implemented in this wrapper, and I apologise for any inconveniences. Feel free to make a PR, or open and Issue if you're able to figure it out!
27+
**Note**: This wrapper supports most of the WandBox API's endpoints, except for the `POST /permlink`. This was because, I couldn't figure out how to work with the endpoint - I kept winding up with `500 - Internal Server Errors`. I'm not sure whether it was a bug in the test data that I was using, or if its a bug in the API itself. Either way, that endpoint has not been implemented in this wrapper, and I apologise for any inconveniences. Feel free to make a PR, or open an issue if you're able to figure it out!

docs/Compiling.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Compiling
2+
3+
GoWandBox (which wraps around the WandBox API) provides two methods to compile your program -
4+
5+
## With GWBProgram
6+
7+
You can compile code by using the `GWBProgram.Execute()` method.
8+
9+
Make sure you've imported `github.com/classPythonAddike/gowandbox` as `gwb`
10+
11+
First initialise a new GWBProgram -
12+
```go
13+
prog := gwb.NewGWBProgram()
14+
15+
prog.Code = `
16+
import gwbutil
17+
gwbutil.say()
18+
gwbutil.say()
19+
` // Main program
20+
21+
// Additional files to use
22+
prog.Codes = []gwb.Program{
23+
{
24+
"gwbutil.py",
25+
"def say(): print(input())",
26+
},
27+
}
28+
29+
// Show warnings
30+
prog.Options = "warning"
31+
prog.Compiler = "cpython-3.8.0" // Use cpython 3.8
32+
prog.Stdin = "123\n456" // Input for the program
33+
prog.SaveCode = true // Save it to a permlink
34+
```
35+
36+
Execute it with `.Execute()`
37+
```go
38+
result, err := prog.Execute(10000) // We want the request to timeout after 10,000 milliseconds
39+
40+
if err != nil {
41+
log.Fatal(err)
42+
/*
43+
`err` is not nil if the response status code is not 200,
44+
if the request timed out,
45+
or an intnernal error ocurred in the wrapper
46+
*/
47+
}
48+
```
49+
50+
You can access information like errors, exit code and output from the `GWBResult` struct.
51+
```go
52+
fmt.Printf("Output during compile time - \"%v\"\n", result.CompilerOutput)
53+
fmt.Printf("Errors during compile time - \"%v\"\n", result.CompilerError)
54+
55+
fmt.Printf("Output of program - \"%v\"\n", result.ProgramOutput)
56+
fmt.Printf("Errors during runtime - \"%v\"\n", result.ProgramError)
57+
58+
fmt.Printf("Exit code - \"%v\"\n", result.Status)
59+
fmt.Printf("Signal - \"%v\"\n", result.Signal)
60+
61+
fmt.Printf("View the program in your browser at \"%v\"\n", result.Url)
62+
fmt.Printf("Permlink to this program - \"%v\"\n", result.Permlink)
63+
```
64+
65+
```
66+
$ go run main.go
67+
Output during compile time - ""
68+
Errors during compile time - ""
69+
Output of program - "123
70+
456
71+
"
72+
Errors during runtime - ""
73+
Exit code - "0"
74+
Signal - ""
75+
View the program in your browser at "https://wandbox.org/permlink/kOJgNvv8flGlApCA"
76+
Permlink to this program - "kOJgNvv8flGlApCA"
77+
```
78+
79+
## With GWBNDProgram
80+
81+
WandBox offers an alternate method to compile your code - by using the `/compile.ndjson` endpoint. While this method is ideal for "streaming" the response, as it returns `NDJSON`, it is not as verbose as the former method.
82+
83+
GoWandBox's API for GWBProgram and GWBNDProgram are very similar.
84+
85+
First, declare your `GWBNDProgram` -
86+
```go
87+
prog := gwb.NewGWBNDProgram()
88+
89+
prog.Code = `
90+
import gwbutil, time
91+
gwbutil.say()
92+
time.sleep(5)
93+
gwbutil.say()
94+
`
95+
prog.Codes = []gwb.Program{
96+
{
97+
"gwbutil.py",
98+
"def say(): print(input())",
99+
},
100+
}
101+
prog.Options = "warning"
102+
prog.Compiler = "cpython-3.8.0"
103+
prog.Stdin = "123\n456"
104+
```
105+
106+
Then, execute your code -
107+
```go
108+
result, err := prog.Execute(10000) // Result is of the type `GWBNDReader`
109+
110+
if err != nil {
111+
log.Fatal(err)
112+
}
113+
```
114+
115+
You can obtain the data with the `.Next()` method of the `GWBNDReader` -
116+
```go
117+
for {
118+
msg, err := result.Next() // msg is of the type GWBNDMessage
119+
120+
if err == io.EOF {
121+
break
122+
} else if err == nil {
123+
fmt.Printf("Type - %v, Data - %v", msg.Type, msg.Data)
124+
} else {
125+
log.Fatal(err)
126+
}
127+
}
128+
```
129+
130+
```
131+
$ go run main.go
132+
Type - Control, Data - Start
133+
Type - StdOut, Data - 123
134+
Type - StdOut, Data - 456
135+
Type - ExitCode, Data - 0
136+
Type - Control, Data - Finish
137+
```

docs/README.md

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,45 @@
1313

1414
A simple wrapper for the WandBox API, written in Golang!
1515

16+
**Note**: This wrapper supports most of the WandBox API's endpoints, except for the `POST /permlink`. This was because, I couldn't figure out how to work with the endpoint - I kept winding up with `500 - Internal Server Errors`. I'm not sure whether it was a bug in the test data that I was using, or if its a bug in the API itself. Either way, that endpoint has not been implemented in this wrapper, and I apologise for any inconveniences. Feel free to make a PR, or open an issue if you're able to figure it out!
17+
1618
## Installation
1719

1820
`$ go get github.com/classPythonAddike/gowandbox`
1921

2022

21-
## Usage
23+
## Quick Start
2224

2325
```go
26+
2427
package main
2528

2629
import (
27-
"fmt"
28-
gwb "github.com/classPythonAddike/gowandbox"
30+
"log"
31+
32+
gwb "github.com/classPythonAddike/gowandbox"
2933
)
3034

3135
func main() {
3236

33-
prog := NewGWBProgram()
37+
prog := gwb.NewGWBProgram()
3438

35-
prog.Code = "import gwbutil\n\ngwbutil.say()\ngwbutil.say()" // Code for the main program
39+
prog.Code = "print('Hello, World!')" // Code for the main program
40+
prog.Compiler = "cpython-3.8.0" // Use cpython, 3.8 to run your code
3641

37-
// Other files to create
38-
prog.Codes = []Program{
39-
{
40-
"gwbutil.py",
41-
"def say():\nprint(input())",
42-
},
43-
}
42+
result, err := prog.Execute(10000) // 10000 milliseconds is the timeout
4443

45-
prog.Options = "warning" // Show warnings
46-
prog.Compiler = "cpython-3.8.0" // Use cpython, 3.8 to run your code
47-
prog.Stdin = "123\n456" // Specify input for the program
44+
if err != nil {
45+
log.Fatal(err)
46+
}
4847

49-
result, err := prog.Execute(10000) // 10000 milliseconds is the timeout
48+
log.Printf("Output: %v", result.ProgramOutput)
49+
}
5050

51-
if err != nil {
52-
fmt.Fatal(err)
53-
}
51+
```
5452

55-
fmt.Sprintf("Output: %v\n", result.ProgramOutput)
56-
/*
57-
Use result.CompilerOutput for output during compile time
58-
Use result.CompilerError for errors during compile time
59-
Use result.CompilerMessage for both put together
53+
```
54+
$ go run main.go
55+
Output: Hello, World!
6056
61-
Use result.ProgramOutput for output during runtime
62-
Use result.ProgramError for errors during runtime
63-
Use result.ProgramMessage for both put together
64-
*/
65-
}
6657
```

docs/_sidebar.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* [Home](/)
2+
* [Compiling](/Compiling.md)

docs/index.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@
66
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
77
<meta name="description" content="Simple API wrapper fo WandBox, written in Go">
88
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
9-
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
9+
10+
<link
11+
rel="stylesheet"
12+
href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple-dark.css"
13+
>
14+
15+
<link rel="preconnect" href="https://fonts.googleapis.com">
16+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
17+
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@500&display=swap" rel="stylesheet">
1018
</head>
1119
<body>
1220
<div id="app"></div>
1321
<script>
1422
window.$docsify = {
1523
name: 'GoWandBox',
16-
repo: 'https://github.com/classPythonAddike/gowandbox'
24+
repo: 'https://github.com/classPythonAddike/gowandbox',
25+
loadSidebar: true,
26+
subMaxLevel: 3
1727
}
1828
</script>
1929
<!-- Docsify v4 -->
@@ -23,4 +33,10 @@
2333
src="https://cdn.jsdelivr.net/npm/docsify-progress@latest/dist/progress.min.js">
2434
</script>
2535
</body>
36+
37+
<style>
38+
:root {
39+
--code-font-family: 'Jetbrains Mono';
40+
}
41+
</style>
2642
</html>

0 commit comments

Comments
 (0)