-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample.go
147 lines (107 loc) · 3.65 KB
/
sample.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main;
// -- IMPORTS
import ( "html"
"io"
"log"
"net/http"
"net/url"
"strconv" );
// -- DEFINITIONS
// ~~
// ~~
// ~~
// ~~
// ~~
// -- TYPES
// -- TYPES
type StringStack struct {
ElementArray []string;
}
// -- INQUIRIES
func ( stack * StringStack ) IsEmpty( ) bool {
return len( stack.ElementArray ) == 0;
}
// -- OPERATIONS
func ( stack * StringStack ) Push( element string ) {
stack.ElementArray = append( stack.ElementArray, element );
}
// ~~
func ( stack * StringStack ) Pop( ) string {
var element string;
element = stack.ElementArray[ len( stack.ElementArray ) - 1 ];
stack.ElementArray = stack.ElementArray[ : len( stack.ElementArray ) - 1 ];
return element;
}
// -- TYPES
type Int32Stack struct {
ElementArray []int32;
}
// -- INQUIRIES
func ( stack * Int32Stack ) IsEmpty( ) bool {
return len( stack.ElementArray ) == 0;
}
// -- OPERATIONS
func ( stack * Int32Stack ) Push( element int32 ) {
stack.ElementArray = append( stack.ElementArray, element );
}
// ~~
func ( stack * Int32Stack ) Pop( ) int32 {
var element int32;
element = stack.ElementArray[ len( stack.ElementArray ) - 1 ];
stack.ElementArray = stack.ElementArray[ : len( stack.ElementArray ) - 1 ];
return element;
}
// -- FUNCTIONS
func HandleRootPage( response_writer http.ResponseWriter, request * http.Request ) {
var boolean bool;
var natural uint;
var integer int;
var real float64;
var escaped_html_text, escaped_url_text, text string;
var integer_stack Int32Stack;
boolean = true;
natural = 10;
integer = 20;
real = 30.0;
text = "text";
escaped_url_text = "&escaped text?";
escaped_html_text = "<escaped text/>";
integer_stack.Push( 10 );
integer_stack.Push( 20 );
integer_stack.Push( 30 );
io.WriteString( response_writer, "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>" );
io.WriteString( response_writer, html.EscapeString( request.URL.Path ) );
io.WriteString( response_writer, "</title>\n</head>\n<body>\n" );
if ( boolean ) {
io.WriteString( response_writer, "\n" );
io.WriteString( response_writer, html.EscapeString( "URL : " + request.URL.Path ) );
io.WriteString( response_writer, "\n<br/>\n" );
io.WriteString( response_writer, strconv.FormatUint( uint64( natural ), 10 ) );
io.WriteString( response_writer, "\n" );
io.WriteString( response_writer, strconv.FormatInt( int64( integer ), 10 ) );
io.WriteString( response_writer, "\n" );
io.WriteString( response_writer, strconv.FormatFloat( float64( real ), 'f', -1, 64 ) );
io.WriteString( response_writer, "\n<br/>\n" );
io.WriteString( response_writer, text );
io.WriteString( response_writer, "\n" );
io.WriteString( response_writer, url.QueryEscape( escaped_url_text ) );
io.WriteString( response_writer, "\n" );
io.WriteString( response_writer, html.EscapeString( escaped_html_text ) );
io.WriteString( response_writer, "\n" );
io.WriteString( response_writer, html.EscapeString( "<%% ignored %>" ) );
io.WriteString( response_writer, "\n<% ignored %%>\n" );
}
io.WriteString( response_writer, "\n<br/>\nStack :\n<br/>\n" );
for !integer_stack.IsEmpty() {
io.WriteString( response_writer, "\n" );
io.WriteString( response_writer, strconv.FormatInt( int64( integer_stack.Pop() ), 10 ) );
io.WriteString( response_writer, "\n" );
}
io.WriteString( response_writer, "\n</body>\n</html>" );
}
// ~~
func main() {
http.HandleFunc( "/", HandleRootPage );
log.Println( "Listening on http://localhost:8080" );
log.Fatal( http.ListenAndServe( ":8080", nil ) );
}