From 689b1a804bfa0baf41a59c2ace1463766db460b3 Mon Sep 17 00:00:00 2001 From: Azareal Date: Mon, 5 Dec 2016 07:21:17 +0000 Subject: [PATCH] Static files are now served from memory. This feature's a little experimental, so it will need a lot of testing i.i Added an executable file. Only works on Windows, if it doesn't work, then try building it for yourself with build.bat or go build Tweaked run.bat to make it more firewall friendly. It now generates an executable. Moved the files around to make it more organised. Added build.bat which you can use to build the program for you and install the libraries the software depends on. --- .gitignore | 2 +- README.md | 4 +- build.bat | 1 + src/config.go => config.go | 0 src/data.sql => data.sql | 0 src/errors.go => errors.go | 16 +++--- files.go | 51 ++++++++++++++++++ src/forum.go => forum.go | 0 grosolo.exe | Bin 0 -> 9239040 bytes src/group.go => group.go | 0 src/main.go => main.go | 28 +++++++++- src/pages.go => pages.go | 7 +++ {src/pages => pages}/test.html | 0 {src/public => public}/global.js | 0 {src/public => public}/jquery-1.12.3.min.js | 0 {src/public => public}/main.css | 0 {src/public => public}/white-dot.jpg | Bin src/reply.go => reply.go | 0 src/routes.go => routes.go | 24 ++++++++- run.bat | 3 ++ src/run.bat | 2 - .../account-own-edit-avatar-success.html | 0 .../account-own-edit-avatar.html | 0 .../account-own-edit-success.html | 0 .../account-own-edit-username.html | 0 .../account-own-edit.html | 0 .../templates => templates}/create-topic.html | 0 {src/templates => templates}/custom_page.html | 0 {src/templates => templates}/edit-topic.html | 0 {src/templates => templates}/error.html | 0 {src/templates => templates}/footer.html | 0 {src/templates => templates}/forum.html | 0 {src/templates => templates}/forums.html | 0 {src/templates => templates}/header.html | 0 {src/templates => templates}/login.html | 0 {src/templates => templates}/menu.html | 0 {src/templates => templates}/overview.html | 0 {src/templates => templates}/page.html | 0 .../templates => templates}/panel-forums.html | 0 {src/templates => templates}/register.html | 0 {src/templates => templates}/topic.html | 0 {src/templates => templates}/topics.html | 0 src/topic.go => topic.go | 0 src/user.go => user.go | 0 src/utils.go => utils.go | 0 45 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 build.bat rename src/config.go => config.go (100%) rename src/data.sql => data.sql (100%) rename src/errors.go => errors.go (87%) create mode 100644 files.go rename src/forum.go => forum.go (100%) create mode 100644 grosolo.exe rename src/group.go => group.go (100%) rename src/main.go => main.go (91%) rename src/pages.go => pages.go (90%) rename {src/pages => pages}/test.html (100%) rename {src/public => public}/global.js (100%) rename {src/public => public}/jquery-1.12.3.min.js (100%) rename {src/public => public}/main.css (100%) rename {src/public => public}/white-dot.jpg (100%) rename src/reply.go => reply.go (100%) rename src/routes.go => routes.go (96%) create mode 100644 run.bat delete mode 100644 src/run.bat rename {src/templates => templates}/account-own-edit-avatar-success.html (100%) rename {src/templates => templates}/account-own-edit-avatar.html (100%) rename {src/templates => templates}/account-own-edit-success.html (100%) rename {src/templates => templates}/account-own-edit-username.html (100%) rename {src/templates => templates}/account-own-edit.html (100%) rename {src/templates => templates}/create-topic.html (100%) rename {src/templates => templates}/custom_page.html (100%) rename {src/templates => templates}/edit-topic.html (100%) rename {src/templates => templates}/error.html (100%) rename {src/templates => templates}/footer.html (100%) rename {src/templates => templates}/forum.html (100%) rename {src/templates => templates}/forums.html (100%) rename {src/templates => templates}/header.html (100%) rename {src/templates => templates}/login.html (100%) rename {src/templates => templates}/menu.html (100%) rename {src/templates => templates}/overview.html (100%) rename {src/templates => templates}/page.html (100%) rename {src/templates => templates}/panel-forums.html (100%) rename {src/templates => templates}/register.html (100%) rename {src/templates => templates}/topic.html (100%) rename {src/templates => templates}/topics.html (100%) rename src/topic.go => topic.go (100%) rename src/user.go => user.go (100%) rename src/utils.go => utils.go (100%) diff --git a/.gitignore b/.gitignore index 580d0deb..dbc49e4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -src/uploads/* +uploads/* bin/* \ No newline at end of file diff --git a/README.md b/README.md index 35f5632e..f3b8fb54 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Set the password column of your user account in the database to what you want yo # Run the program -go run errors.go main.go pages.go reply.go routes.go topic.go user.go utils.go forum.go group.go config.go +go run errors.go main.go pages.go reply.go routes.go topic.go user.go utils.go forum.go group.go files.go config.go Alternatively, you could run the run.bat batch file on Windows. @@ -64,5 +64,3 @@ Revamp the system for serving static files to make it much faster. Tweak the CSS to make it responsive. Add a forum cache. - -Cache the static files in memory. diff --git a/build.bat b/build.bat new file mode 100644 index 00000000..363fa9f1 --- /dev/null +++ b/build.bat @@ -0,0 +1 @@ +go build \ No newline at end of file diff --git a/src/config.go b/config.go similarity index 100% rename from src/config.go rename to config.go diff --git a/src/data.sql b/data.sql similarity index 100% rename from src/data.sql rename to data.sql diff --git a/src/errors.go b/errors.go similarity index 87% rename from src/errors.go rename to errors.go index c0d12ad7..a66c7082 100644 --- a/src/errors.go +++ b/errors.go @@ -39,8 +39,7 @@ func LocalError(errmsg string, w http.ResponseWriter, r *http.Request, user User } func LoginRequired(w http.ResponseWriter, r *http.Request, user User) { - errmsg := "You need to login to do that." - pi := Page{"Local Error","error",user,tList,errmsg} + pi := Page{"Local Error","error",user,tList,"You need to login to do that."} var b bytes.Buffer templates.ExecuteTemplate(&b,"error.html", pi) @@ -87,8 +86,7 @@ func NoPermissionsJSQ(w http.ResponseWriter, r *http.Request, user User, is_js s } func Banned(w http.ResponseWriter, r *http.Request, user User) { - errmsg := "You have been banned, thus you do not permission to do that." - pi := Page{"Local Error","error",user,tList,errmsg} + pi := Page{"Banned","error",user,tList,"You have been banned from this site."} var b bytes.Buffer templates.ExecuteTemplate(&b,"error.html", pi) errpage := b.String() @@ -97,30 +95,28 @@ func Banned(w http.ResponseWriter, r *http.Request, user User) { } func BannedJSQ(w http.ResponseWriter, r *http.Request, user User, is_js string) { - errmsg := "You have been banned from this site." if is_js == "0" { - pi := Page{"Local Error","error",user,tList,errmsg} + pi := Page{"Banned","error",user,tList,"You have been banned from this site."} var b bytes.Buffer templates.ExecuteTemplate(&b,"error.html", pi) errpage := b.String() w.WriteHeader(403) fmt.Fprintln(w,errpage) } else { - http.Error(w,"{'errmsg': '" + errmsg + "'}",403) + http.Error(w,"{'errmsg': 'You have been banned from this site.'}",403) } } func LoginRequiredJSQ(w http.ResponseWriter, r *http.Request, user User, is_js string) { - errmsg := "You need to login to do that." if is_js == "0" { - pi := Page{"Local Error","error",user,tList,errmsg} + pi := Page{"Local Error","error",user,tList,"You need to login to do that."} var b bytes.Buffer templates.ExecuteTemplate(&b,"error.html", pi) errpage := b.String() w.WriteHeader(401) fmt.Fprintln(w,errpage) } else { - http.Error(w,"{'errmsg': '" + errmsg + "'}",401) + http.Error(w,"{'errmsg': 'You need to login to do that.'}",401) } } diff --git a/files.go b/files.go new file mode 100644 index 00000000..519f4f14 --- /dev/null +++ b/files.go @@ -0,0 +1,51 @@ +package main +import "io" +import "os" +import "errors" + +type SFile struct +{ + Data []byte + Pos int64 + Length int64 + Mimetype string + Info os.FileInfo + FormattedModTime string +} + +func (r SFile) Read(b []byte) (n int, err error) { + n = 0 + if r.Pos > r.Length { + return n, io.EOF + } + + size := cap(b) + if size > 0 { + for n < size { + b[n] = r.Data[r.Pos] + n++ + if r.Pos == r.Length { + break + } + r.Pos++ + } + } + return n, nil +} + +func (r SFile) Seek(offset int64, whence int) (int64, error) { + if offset < 0 { + return 0, errors.New("negative position") + } + switch whence { + case 0: + r.Pos = offset + case 1: + r.Pos += offset + case 2: + r.Pos = r.Length + offset + default: + return 0, errors.New("invalid whence") + } + return r.Pos, nil +} \ No newline at end of file diff --git a/src/forum.go b/forum.go similarity index 100% rename from src/forum.go rename to forum.go diff --git a/grosolo.exe b/grosolo.exe new file mode 100644 index 0000000000000000000000000000000000000000..216a9b3ff1533d3adab01f9cfb54fd62eb3557f3 GIT binary patch literal 9239040 zcmeFa33yaR_BP%ufyiQlxJ2+`gDr+l0*C}9V_5BA)TlTH1q})s7BwnpRMbX-(l%G) zh>99D;uZxpDubw~0R%FxxW|>~xZD<$xTAu6?|Z85(&pH7c@H*cuhx&XCzC+q}Zrjf1+j+Lnx2uih<<@uf`Ol4aZLUDkbta6{P zgDQd+@P|VDle(T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