Skip to content

Commit

Permalink
Replace JSON struct wrappers with struct tags
Browse files Browse the repository at this point in the history
move (My)SQL initialization stuff to sql script to be run every time
  • Loading branch information
Eggbertx committed May 14, 2019
1 parent bb9cb5a commit fa72398
Show file tree
Hide file tree
Showing 16 changed files with 437 additions and 693 deletions.
24 changes: 0 additions & 24 deletions ROADMAP.md

This file was deleted.

2 changes: 1 addition & 1 deletion html/error/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<h1>404: File not found</h1>
<img src="/error/lol 404.gif" border="0" alt="">
<p>The requested file could not be found on this server. Are you just typing random stuff in the address bar? If you followed a link from this site here, then post <a href="/site">here</a></p>
<hr><address>http://gochan.org powered by Gochan v2.6.1</address>
<hr><address>http://gochan.org powered by Gochan v2.7.0</address>
</body>
</html>
2 changes: 1 addition & 1 deletion html/error/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<h1>500: Internal Server error</h1>
<img src="/error/derpy server.gif" border="0" alt="">
<p>The server encountered an error while trying to serve the page, and we apologize for the inconvenience. The <a href="https://en.wikipedia.org/wiki/Idiot">system administrator</a> will try to fix things as soon has he/she/it can.</p>
<hr><address>http://gochan.org powered by Gochan v2.6.1</address>
<hr><address>http://gochan.org powered by Gochan v2.7.0</address>
</body>
</html>
31 changes: 19 additions & 12 deletions initialsetupdb.sql → initdb.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
-- Initial setup file for Gochan

-- Turn off warnings in case tables are already there.
SET sql_notes=0;
-- Gochan MySQL startup/update script
-- DO NOT DELETE

CREATE TABLE IF NOT EXISTS `DBPREFIXannouncements` (
`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
Expand Down Expand Up @@ -42,6 +40,18 @@ CREATE TABLE IF NOT EXISTS `DBPREFIXbanlist` (
`can_appeal` TINYINT(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
ALTER TABLE `DBPREFIXbanlist`
CHANGE IF EXISTS `banned_by` `staff` VARCHAR(50) NOT NULL,
CHANGE IF EXISTS `id` `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
CHANGE IF EXISTS `expires` `expires` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
CHANGE IF EXISTS `boards` `boards` VARCHAR(255) NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS `type` TINYINT UNSIGNED NOT NULL DEFAULT '3',
ADD COLUMN IF NOT EXISTS `name_is_regex` TINYINT(1) DEFAULT '0',
ADD COLUMN IF NOT EXISTS `filename` VARCHAR(255) NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS `file_checksum` VARCHAR(255) NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS `permaban` TINYINT(1) DEFAULT '0',
ADD COLUMN IF NOT EXISTS `can_appeal` TINYINT(1) DEFAULT '1',
DROP COLUMN IF EXISTS `message`;

CREATE TABLE IF NOT EXISTS `DBPREFIXbannedhashes` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
Expand All @@ -62,7 +72,6 @@ CREATE TABLE IF NOT EXISTS `DBPREFIXboards` (
`section` VARCHAR(45) NOT NULL,
`max_image_size` INT UNSIGNED NOT NULL DEFAULT 4718592,
`max_pages` TINYINT UNSIGNED NOT NULL DEFAULT 11,
`locale` VARCHAR(10) NOT NULL DEFAULT 'en-us',
`default_style` VARCHAR(45) NOT NULL,
`locked` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
`created_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand All @@ -79,6 +88,8 @@ CREATE TABLE IF NOT EXISTS `DBPREFIXboards` (
PRIMARY KEY (`id`),
UNIQUE (`dir`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=0;
ALTER TABLE `DBPREFIXboards`
DROP COLUMN IF EXISTS `locale`;

CREATE TABLE IF NOT EXISTS `DBPREFIXembeds` (
`id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
Expand Down Expand Up @@ -163,7 +174,6 @@ CREATE TABLE IF NOT EXISTS `DBPREFIXposts` (
`tag` VARCHAR(5) NOT NULL DEFAULT '',
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`autosage` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
`poster_authority` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
`deleted_timestamp` TIMESTAMP,
`bumped` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`stickied` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
Expand All @@ -176,6 +186,9 @@ CREATE TABLE IF NOT EXISTS `DBPREFIXposts` (
KEY `file_checksum` (`file_checksum`),
KEY `stickied` (`stickied`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;
ALTER TABLE `DBPREFIXposts`
DROP COLUMN IF EXISTS `sillytag`,
DROP COLUMN IF EXISTS `poster_authority`;

CREATE TABLE IF NOT EXISTS `DBPREFIXreports` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
Expand Down Expand Up @@ -219,12 +232,6 @@ CREATE TABLE IF NOT EXISTS `DBPREFIXstaff` (
UNIQUE (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;

-- create a temp table with the same columns as the posts table to be stored in memory
-- This is currently not used, and commented out.
-- CREATE TABLE IF NOT EXISTS `DBPREFIXtempposts` SELECT * FROM DBPREFIXposts;
-- ALTER TABLE `DBPREFIXtempposts` CHANGE `message` `message` VARCHAR(1024);
-- ALTER TABLE `DBPREFIXtempposts` ENGINE=MEMORY;

CREATE TABLE IF NOT EXISTS `DBPREFIXwordfilters` (
`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
`from` VARCHAR(75) NOT NULL,
Expand Down
45 changes: 45 additions & 0 deletions src/api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"fmt"
"testing"
)

type Color struct {
Red int `json:"red"`
Green int `json:"green"`
Blue int `json:"blue"`
}

func TestAPI(t *testing.T) {
var api string
var err error

if api, err = marshalAPI("colorsSlice", []Color{
Color{255, 0, 0},
Color{0, 255, 0},
Color{0, 0, 255},
}, true); err != nil {
t.Fatal(err.Error())
}
fmt.Println("API slice: " + api)

if api, err = marshalAPI("colorsMap", map[string]Color{
"red": Color{255, 0, 0},
"green": Color{0, 255, 0},
"blue": Color{0, 0, 255},
}, true); err != nil {
t.Fatal(err.Error())
}
fmt.Println("API map: " + api)

if api, err = marshalAPI("color", Color{255, 0, 0}, true); err != nil {
t.Fatal(err.Error())
}
fmt.Println("API struct: " + api)

if api, err = marshalAPI("error", "Some error", false); err != nil {
t.Fatal(err.Error())
}
fmt.Println("API string: " + api)
}
Loading

0 comments on commit fa72398

Please sign in to comment.