-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
executable file
·164 lines (115 loc) · 5.93 KB
/
README
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright 2010 Abiola Ibrahim <[email protected]>. All rights reserved.
// Use of this source code is governed by New BSD License
// http://www.opensource.org/licenses/bsd-license.php
// The content and logo is governed by Creative Commons Attribution 3.0
// The mascott is a property of Go governed by Creative Commons Attribution 3.0
// http://creativecommons.org/licenses/by/3.0/
gopages - http://code.google.com/p/gopages
======
A simple web framework with the objective of making web development in go easier
With gopages you create web pages and embed codes in <?go ?> tags.
It automatically adds http handlers for all pages with the
extensions you specify in the settings file and serves all files
in the source folder with the exception of the source codes.
gopages is compiled before execution.
REQUIREMENTS
============
To use gopages, gobuild (http://code.google.com/p/gobuild) is required
-gobuild executable must be copied to your $GOBIN for gopages to access it
-build gopages using gobuild (or download the binary)
-copy gopages to your $GOBIN or add it to your $PATH or anywhere accessible
It is easy to use.
a simple hello world example
create a folder 'src' and create an index.ghtml file in it
with the contents
<html>
<body>
<?go print("<h1>Hello World</h1>") ?>
</body>
</html>
then create a pages.settings file in the root folder (parent to src) with the contents
extensions{ ghtml }
handle { ALL }
srcfolder { src }
default { index }
then create a hello.go in the root folder with the content
package main
import "pages" //generated package
func main(){
pages.Run(":9999") //start server on localhost:9999
}
open terminal, navigate to project root and run gopages
then run ./hello
finally, point your browser to localhost:9999
HOW IT WORKS
============
gopages generates go source codes to a "pages" directory in your package root folder.
The filenames of go source codes generated follow the rules
removes all '.' e.g. hello.ghtml will be helloghtml.go
names the file from the package root folder and removes all '/' e.g. src/hello.ghtml will now be srchelloghtml.go
inside each generated source file there is an handler function
func Rendersourcecodename(conn *http.Conn, request *http.Request)
e.g. hello.ghtml will generate func Rendersrchellohtml(conn *http.Conn, request *http.Request)
in case you want to add an handler manually though you mostly won't need to
you should add the handler before calling pages.Run like the example below
package main
import "pages"
func main(){
http.Handle("/manual", http.HandlerFunc(pages.Rendersrchelloghtml));
pages.Run(":9999")
}
GETTING STARTED
===============
firstly, u must create a pages.settings File in your package root with the following rules
extensions { ghtml }
handle { ALL }
srcfolder { src }
default { index }
extensions - contains file extensions of html pages you created the gopages way in the srcfolder
you can choose any extension. I used ghtml cos it sounds goish.
and you can have more than one e.g. extensions { ghtml do gsp }
handle - contains pages to automatically add handlers for and there are keywords ALL and EXCEPT
ALL - will handle all pages in src folder with the extensions you specify
EXCEPT - will handle all but the pages that follow e.g. handle { EXCEPT hello.ghtml echo.ghtml }
- you can also list the pages to handle e.g. handle { hello.ghtml hello.html }
I added this cos there may be need to manually handle some pages
srcfolder - folder where the source files are located (just one value)
default - the page to load by default (one value) e.g. the Hello World example loads index by default
Only the braces matters, you can separate with any whitespace character
You may be wondering why I didn't use common standards like XML, I just thought
this is easy enough to write. But as the project grows, there may need for XML.
Then create your webpages with the rules
Design your webpages normally and embed your codes in <?go ?> tags just like php
if you need to import any package, your webpage must begin with "{{ libraries to import }}" without quotes
e.g. {{ strconv io ioutil }} <html> <head> ...
you can separate them with any whitespace character(s)
there are some built-in variables and functions to use:
conn *http.Conn, request *http.Request, formValue(key string), print(text ...interface{})
- formValue(key string) to retrieve value from GET or POST requests
- print(text ...interface) to print any data type
- to do other things, read the godoc for http.Conn and http.Request
All your pages and anything you want gopages to handle must be in the srcfolder
you specify in the settings file, you may add other handlers manually if you need
to access other locations
the srcfolder and pages folder (where generated codes are stored) are not accessible
through http requests which is in most cases the web browser.
To access your pages from web browser, use the path without the file extension.
Just like the hello world example above, the address to locate the index.ghtml file is localhost:9999/index
NOTE:
having index.ghtml and index.do in same folder where gopages is handling both ghtml and do
will lead to having only one, with one overwriting the other, the one generated last.
Finally, in your main.main func you must call pages.Run for all handlers to be added.
navigate to your package root, run gopages and execute the resulting executable
or run "gopages -run" without quotes to run the executable after successful build
EXAMPLES
========
to run the examples, extract the examples and navigate to the folder
open terminal and run gopages
run ./main
and finally navigate your browser to http://localhost:9999
Enjoy
To use makefile with gopages instead of gobuild (if you'd prefer)
run gopages -make "flags" e.g. gopages -make "install"
gopages assume make is located in '/usr/bin/make'
COMMENTS and TIPS are welcome in my inbox and blog(abiola89.blogspot.com). Anyone interested in the
project can mail me too.