1. Dobrosław Żybort
  2. PastebinGo

Commits

Dobrosław Żybort  committed f4e8048

Go fmt all files

  • Participants
  • Parent commits a55f036
  • Branches default

Comments (0)

Files changed (7)

File config.go

View file
-// config
+// config
 package main
 
 const (

File database.go

View file
-// database
+// database
 package main
 
-//=============================================================================
+//=============================================================================
 
 func getSomePastes(nr int, offset int64, ctx *Context) (pastes []Paste, err error) {
 	rows, err := ctx.Database.Query(`
 	if err != nil {
 		return 0, err
 	} else {
-		// row := con.QueryRow("select paste_id from pastes order by paste_id desc limit 1")
-		// err = row.Scan(&lastId)
+		// row := con.QueryRow("select paste_id from pastes order by paste_id desc limit 1")
+		// err = row.Scan(&lastId)
 		lastId, err = result.LastInsertId()
 	}
 	return lastId, err

File database_init_mysql.go

View file
-// +build mysql
-
-// database_init_mysql
-package main
-
-import (
-	"database/sql"
-	"fmt"
-	_ "github.com/ziutek/mymysql/godrv"
-	"net/http"
-)
-
-//=============================================================================
-
-func dbInit() error {
-	con, err := sql.Open("mymysql",
-		fmt.Sprintf("%s:%s:%s*%s/%s/%s",
-			DB_PROTOCOL,
-			DB_ADDRESS,
-			DB_PORT,
-			DB_NAME,
-			DB_USER,
-			DB_PASS))
-	defer con.Close()
-
-	if err != nil {
-		panic(err)
-	}
-
-	sqls := []string{`
-		CREATE TABLE IF NOT EXISTS pastes ( 
-			Paste_ID bigint(20) NOT NULL AUTO_INCREMENT,
-			Datetime datetime,
-			Title varchar(255) DEFAULT 'Untitled',
-			Author varchar(255) DEFAULT 'Anonymous',
-			User_ID bigint(20) DEFAULT 1,
-			Protection integer,
-			Syntax varchar(255) DEFAULT 'plaintext',
-			URL longtext,
-			Lifespan integer,
-			IP varchar(225),
-			Data longtext,
-			INDEX (Paste_ID)
-		) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_general_ci
-		`, `
-		CREATE TABLE IF NOT EXISTS users (
-			User_ID bigint(20) NOT NULL AUTO_INCREMENT,
-			Display_name varchar(255) UNIQUE,
-			Password tinyblob,
-			INDEX (User_ID)
-		) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_general_ci
-		`, `
-		INSERT IGNORE INTO users (Display_name) VALUES('Anonymous')
-		`,
-	}
-	for _, sql := range sqls {
-		_, err = con.Exec(sql)
-		if err != nil {
-			fmt.Printf("%q: %s\n", err, sql)
-			return err
-		}
-	}
-
-	return nil
-}
-
-func dbOpen(req *http.Request) *sql.DB {
-	con, err := sql.Open("mymysql",
-		fmt.Sprintf("%s:%s:%s*%s/%s/%s",
-			DB_PROTOCOL,
-			DB_ADDRESS,
-			DB_PORT,
-			DB_NAME,
-			DB_USER,
-			DB_PASS))
-	if err != nil {
-		panic(err)
-	}
-
-	return con
-}
+// +build mysql
+
+// database_init_mysql
+package main
+
+import (
+	"database/sql"
+	"fmt"
+	_ "github.com/ziutek/mymysql/godrv"
+	"net/http"
+)
+
+//=============================================================================
+
+func dbInit() error {
+	con, err := sql.Open("mymysql",
+		fmt.Sprintf("%s:%s:%s*%s/%s/%s",
+			DB_PROTOCOL,
+			DB_ADDRESS,
+			DB_PORT,
+			DB_NAME,
+			DB_USER,
+			DB_PASS))
+	defer con.Close()
+
+	if err != nil {
+		panic(err)
+	}
+
+	sqls := []string{`
+		CREATE TABLE IF NOT EXISTS pastes ( 
+			Paste_ID bigint(20) NOT NULL AUTO_INCREMENT,
+			Datetime datetime,
+			Title varchar(255) DEFAULT 'Untitled',
+			Author varchar(255) DEFAULT 'Anonymous',
+			User_ID bigint(20) DEFAULT 1,
+			Protection integer,
+			Syntax varchar(255) DEFAULT 'plaintext',
+			URL longtext,
+			Lifespan integer,
+			IP varchar(225),
+			Data longtext,
+			INDEX (Paste_ID)
+		) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_general_ci
+		`, `
+		CREATE TABLE IF NOT EXISTS users (
+			User_ID bigint(20) NOT NULL AUTO_INCREMENT,
+			Display_name varchar(255) UNIQUE,
+			Password tinyblob,
+			INDEX (User_ID)
+		) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_general_ci
+		`, `
+		INSERT IGNORE INTO users (Display_name) VALUES('Anonymous')
+		`,
+	}
+	for _, sql := range sqls {
+		_, err = con.Exec(sql)
+		if err != nil {
+			fmt.Printf("%q: %s\n", err, sql)
+			return err
+		}
+	}
+
+	return nil
+}
+
+func dbOpen(req *http.Request) *sql.DB {
+	con, err := sql.Open("mymysql",
+		fmt.Sprintf("%s:%s:%s*%s/%s/%s",
+			DB_PROTOCOL,
+			DB_ADDRESS,
+			DB_PORT,
+			DB_NAME,
+			DB_USER,
+			DB_PASS))
+	if err != nil {
+		panic(err)
+	}
+
+	return con
+}

File database_init_sqlite.go

View file
-// +build !mysql
-
-// database_init_sqlite
-package main
-
-import (
-	"database/sql"
-	"fmt"
-	_ "github.com/mattn/go-sqlite3"
-	"net/http"
-)
-
-//=============================================================================
-
-func dbInit() error {
-	con, err := sql.Open("sqlite3", "./data/pastebingo.db")
-	defer con.Close()
-
-	if err != nil {
-		panic(err)
-	}
-
-	sqls := []string{`
-		CREATE TABLE IF NOT EXISTS pastes ( 
-			Paste_ID integer PRIMARY KEY AUTOINCREMENT NOT NULL, 
-			Datetime datetime, 
-			Title varchar(255) DEFAULT 'Untitled', 
-			Author varchar(255) DEFAULT 'Anonymous', 
-			User_ID integer DEFAULT 1, 
-			Protection integer, 
-			Syntax varchar(255) DEFAULT 'plaintext', 
-			URL longtext, 
-			Lifespan integer, 
-			IP varchar(225), 
-			Data longtext
-		)`, `
-		CREATE TABLE IF NOT EXISTS users (
-			User_ID integer PRIMARY KEY AUTOINCREMENT NOT NULL,
-			Display_name varchar(255) UNIQUE,
-			Password blob(64)
-		)`, `
-		INSERT OR IGNORE INTO users (Display_name) VALUES('Anonymous')
-		`,
-	}
-	for _, sql := range sqls {
-		_, err = con.Exec(sql)
-		if err != nil {
-			fmt.Printf("%q: %s\n", err, sql)
-			return err
-		}
-	}
-
-	return nil
-}
-
-func dbOpen(req *http.Request) *sql.DB {
-	con, err := sql.Open("sqlite3", "./data/pastebingo.db")
-	if err != nil {
-		panic(err)
-	}
-
-	return con
-}
+// +build !mysql
+
+// database_init_sqlite
+package main
+
+import (
+	"database/sql"
+	"fmt"
+	_ "github.com/mattn/go-sqlite3"
+	"net/http"
+)
+
+//=============================================================================
+
+func dbInit() error {
+	con, err := sql.Open("sqlite3", "./data/pastebingo.db")
+	defer con.Close()
+
+	if err != nil {
+		panic(err)
+	}
+
+	sqls := []string{`
+		CREATE TABLE IF NOT EXISTS pastes ( 
+			Paste_ID integer PRIMARY KEY AUTOINCREMENT NOT NULL, 
+			Datetime datetime, 
+			Title varchar(255) DEFAULT 'Untitled', 
+			Author varchar(255) DEFAULT 'Anonymous', 
+			User_ID integer DEFAULT 1, 
+			Protection integer, 
+			Syntax varchar(255) DEFAULT 'plaintext', 
+			URL longtext, 
+			Lifespan integer, 
+			IP varchar(225), 
+			Data longtext
+		)`, `
+		CREATE TABLE IF NOT EXISTS users (
+			User_ID integer PRIMARY KEY AUTOINCREMENT NOT NULL,
+			Display_name varchar(255) UNIQUE,
+			Password blob(64)
+		)`, `
+		INSERT OR IGNORE INTO users (Display_name) VALUES('Anonymous')
+		`,
+	}
+	for _, sql := range sqls {
+		_, err = con.Exec(sql)
+		if err != nil {
+			fmt.Printf("%q: %s\n", err, sql)
+			return err
+		}
+	}
+
+	return nil
+}
+
+func dbOpen(req *http.Request) *sql.DB {
+	con, err := sql.Open("sqlite3", "./data/pastebingo.db")
+	if err != nil {
+		panic(err)
+	}
+
+	return con
+}

File http.go

View file
-// http
+// http
 package main
 
 import (
 
 type handler func(http.ResponseWriter, *http.Request, *Context) error
 
-//=============================================================================
+//=============================================================================
 
 func (han handler) ServeHTTP(wri http.ResponseWriter, req *http.Request) {
-	// create the context
+	// create the context
 	ctx, err := newContext(req)
 	if err != nil {
 		http.Error(wri, err.Error(), http.StatusInternalServerError)
 	}
 	defer ctx.Close()
 
-	// run the handler, grab error and report it
+	// run the handler, grab error and report it
 	buf := new(httpbuf.Buffer)
 	err = han(buf, req, ctx)
 	if err != nil {
 		return
 	}
 
-	// save session
+	// save session
 	if err = ctx.Session.Save(req, buf); err != nil {
 		http.Error(wri, err.Error(), http.StatusInternalServerError)
 		return
 	}
 
-	// apply the buffered response to the writer
+	// apply the buffered response to the writer
 	buf.Apply(wri)
 	return
 }

File paste.go

View file
-// main
+// main
 package main
 
 import "time"
 	Syntax     string `schema:"paste_syntax"`
 }
 
-//=============================================================================
+//=============================================================================
 
 func NewPaste() *Paste {
 	return &Paste{

File user.go

View file
-// user
+// user
 package main
 
 import (
 	PasswordSecond string `schema:"password2"`
 }
 
-//=============================================================================
+//=============================================================================
 
 func (user *User) SetPassword(password string) {
 	pass, err := scrypt.Key(
 	user.Password = pass
 }
 
-// Login
+// Login
 func userLogin(name, password string, ctx *Context) (user *User, err error) {
 	user, err = getUserData(name, ctx)
 	if err != nil {