Dobrosław Żybort avatar Dobrosław Żybort committed c50229c

Update filenames

Comments (0)

Files changed (8)

databaseInitMysql.go

-// +build mysql
-
-// databaseInitMysql
-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
-}

databaseInitSqlite.go

-// +build sqlite
-
-// databaseInitSqlite
-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
-}

database_init_mysql.go

+// +build mysql
+
+// databaseInitMysql
+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
+}

database_init_sqlite.go

+// +build sqlite
+
+// databaseInitSqlite
+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
+}

handlersPaste.go

-// handlersPaste
-package main
-
-import (
-	//"fmt"
-	"github.com/gorilla/schema"
-	"net/http"
-	"strconv"
-)
-
-//=============================================================================
-
-// showPaste show specific paste (by it's ID)
-func showPaste(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
-	pasteId, err := strconv.ParseInt(req.URL.Query().Get(":id"), 10, 64)
-	if err != nil {
-		panic("Wrong conversion")
-	}
-
-	paste, err := getPasteById(pasteId, ctx)
-
-	if err != nil {
-		http.Redirect(wri, req, reverse("index"), http.StatusNotFound)
-		return
-	}
-
-	paste.DisplayDatetime = paste.Datetime.Format("2006-01-02 15:04:05")
-
-	if paste.Syntax == "no-highlight" {
-		paste.Syntax = ""
-	}
-
-	return T("show.html").Execute(wri, map[string]interface{}{
-		"paste": paste,
-		"ctx":   ctx,
-	})
-}
-
-func showNewPaste(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
-	pasteId, err := strconv.ParseInt(req.URL.Query().Get(":id"), 10, 64)
-	if err != nil {
-		panic("Wrong conversion")
-	}
-
-	paste, err := getPasteById(pasteId, ctx)
-
-	if err != nil {
-		http.Redirect(wri, req, reverse("index"), http.StatusNotFound)
-		return
-	}
-
-	paste.DisplayDatetime = paste.Datetime.Format("2006-01-02 15:04:05")
-
-	if paste.Syntax == "no-highlight" {
-		paste.Syntax = ""
-	}
-
-	newPasteUrl := "http://" + req.Host + reverse("showPaste", "id", pasteId)
-	return T("show.html").Execute(wri, map[string]interface{}{
-		"paste":    paste,
-		"pasteUrl": url(newPasteUrl),
-		"ctx":      ctx,
-	})
-}
-
-func addPaste(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
-	paste := NewPaste()
-	req.ParseForm()
-	pasteData := new(PasteForm)
-	schema.NewDecoder().Decode(pasteData, req.Form)
-	if pasteData.Title != "" {
-		paste.Title = pasteData.Title
-	}
-
-	paste.Data = pasteData.Data
-	if paste.Data == "" {
-		http.Redirect(wri, req, reverse("index"), http.StatusNoContent)
-		return
-	}
-
-	if ctx.User == nil {
-		if pasteData.Author != "" {
-			paste.Author = pasteData.Author
-		}
-	} else {
-		paste.Author = ctx.User.Name
-		paste.UserID = ctx.User.ID
-	}
-	paste.Protection = pasteData.Protection
-	paste.Syntax = pasteData.Syntax
-	paste.IP = req.RemoteAddr
-
-	lastId, err := insertPaste(paste, ctx)
-
-	if err != nil {
-		http.Redirect(wri, req, reverse("index"), http.StatusInternalServerError)
-		return
-	}
-
-	http.Redirect(wri, req, reverse("showNewPaste", "id", lastId, "new", "new"), http.StatusSeeOther)
-	return err
-}

handlersUser.go

-// handlersUser
-package main
-
-import (
-	//"fmt"
-	"github.com/gorilla/schema"
-	"net/http"
-)
-
-//=============================================================================
-
-func loginForm(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
-	if ctx.Session.Values["user"] != nil {
-		http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
-		return
-	}
-	return T("login.html").Execute(wri, map[string]interface{}{
-		"ctx": ctx,
-	})
-}
-
-func login(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
-	req.ParseForm()
-	userData := new(UserForm)
-	schema.NewDecoder().Decode(userData, req.Form)
-
-	if userData.Password == "" {
-		ctx.Session.AddFlash("Password can't be empty")
-		return loginForm(wri, req, ctx)
-	}
-
-	user, err := userLogin(userData.Name, userData.Password, ctx)
-	if err != nil {
-		ctx.Session.AddFlash("Invalid username/password")
-		return loginForm(wri, req, ctx)
-	}
-
-	ctx.Session.Values["user"] = user.ID
-	http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
-	return nil
-}
-
-func logout(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
-	delete(ctx.Session.Values, "user")
-	http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
-	return nil
-}
-
-func registerForm(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
-	if ctx.Session.Values["user"] != nil {
-		http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
-		return
-	}
-	return T("register.html").Execute(wri, map[string]interface{}{
-		"ctx": ctx,
-	})
-}
-
-func register(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
-	req.ParseForm()
-	userData := new(UserForm)
-	schema.NewDecoder().Decode(userData, req.Form)
-	if userData.Password != userData.PasswordSecond {
-		ctx.Session.AddFlash("Passwords not match")
-		return registerForm(wri, req, ctx)
-	}
-
-	if userData.Password == "" {
-		ctx.Session.AddFlash("Password can't be empty")
-		return registerForm(wri, req, ctx)
-	}
-
-	user := &User{
-		Name: userData.Name,
-	}
-	user.SetPassword(userData.Password)
-
-	user.ID, err = createUser(user, ctx)
-	if err != nil {
-		ctx.Session.AddFlash("User with same name already exist")
-		return registerForm(wri, req, ctx)
-	}
-
-	ctx.Session.Values["user"] = user.ID
-	http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
-	return nil
-}

handlers_paste.go

+// handlersPaste
+package main
+
+import (
+	//"fmt"
+	"github.com/gorilla/schema"
+	"net/http"
+	"strconv"
+)
+
+//=============================================================================
+
+// showPaste show specific paste (by it's ID)
+func showPaste(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
+	pasteId, err := strconv.ParseInt(req.URL.Query().Get(":id"), 10, 64)
+	if err != nil {
+		panic("Wrong conversion")
+	}
+
+	paste, err := getPasteById(pasteId, ctx)
+
+	if err != nil {
+		http.Redirect(wri, req, reverse("index"), http.StatusNotFound)
+		return
+	}
+
+	paste.DisplayDatetime = paste.Datetime.Format("2006-01-02 15:04:05")
+
+	if paste.Syntax == "no-highlight" {
+		paste.Syntax = ""
+	}
+
+	return T("show.html").Execute(wri, map[string]interface{}{
+		"paste": paste,
+		"ctx":   ctx,
+	})
+}
+
+func showNewPaste(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
+	pasteId, err := strconv.ParseInt(req.URL.Query().Get(":id"), 10, 64)
+	if err != nil {
+		panic("Wrong conversion")
+	}
+
+	paste, err := getPasteById(pasteId, ctx)
+
+	if err != nil {
+		http.Redirect(wri, req, reverse("index"), http.StatusNotFound)
+		return
+	}
+
+	paste.DisplayDatetime = paste.Datetime.Format("2006-01-02 15:04:05")
+
+	if paste.Syntax == "no-highlight" {
+		paste.Syntax = ""
+	}
+
+	newPasteUrl := "http://" + req.Host + reverse("showPaste", "id", pasteId)
+	return T("show.html").Execute(wri, map[string]interface{}{
+		"paste":    paste,
+		"pasteUrl": url(newPasteUrl),
+		"ctx":      ctx,
+	})
+}
+
+func addPaste(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
+	paste := NewPaste()
+	req.ParseForm()
+	pasteData := new(PasteForm)
+	schema.NewDecoder().Decode(pasteData, req.Form)
+	if pasteData.Title != "" {
+		paste.Title = pasteData.Title
+	}
+
+	paste.Data = pasteData.Data
+	if paste.Data == "" {
+		http.Redirect(wri, req, reverse("index"), http.StatusNoContent)
+		return
+	}
+
+	if ctx.User == nil {
+		if pasteData.Author != "" {
+			paste.Author = pasteData.Author
+		}
+	} else {
+		paste.Author = ctx.User.Name
+		paste.UserID = ctx.User.ID
+	}
+	paste.Protection = pasteData.Protection
+	paste.Syntax = pasteData.Syntax
+	paste.IP = req.RemoteAddr
+
+	lastId, err := insertPaste(paste, ctx)
+
+	if err != nil {
+		http.Redirect(wri, req, reverse("index"), http.StatusInternalServerError)
+		return
+	}
+
+	http.Redirect(wri, req, reverse("showNewPaste", "id", lastId, "new", "new"), http.StatusSeeOther)
+	return err
+}
+// handlersUser
+package main
+
+import (
+	//"fmt"
+	"github.com/gorilla/schema"
+	"net/http"
+)
+
+//=============================================================================
+
+func loginForm(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
+	if ctx.Session.Values["user"] != nil {
+		http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
+		return
+	}
+	return T("login.html").Execute(wri, map[string]interface{}{
+		"ctx": ctx,
+	})
+}
+
+func login(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
+	req.ParseForm()
+	userData := new(UserForm)
+	schema.NewDecoder().Decode(userData, req.Form)
+
+	if userData.Password == "" {
+		ctx.Session.AddFlash("Password can't be empty")
+		return loginForm(wri, req, ctx)
+	}
+
+	user, err := userLogin(userData.Name, userData.Password, ctx)
+	if err != nil {
+		ctx.Session.AddFlash("Invalid username/password")
+		return loginForm(wri, req, ctx)
+	}
+
+	ctx.Session.Values["user"] = user.ID
+	http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
+	return nil
+}
+
+func logout(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
+	delete(ctx.Session.Values, "user")
+	http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
+	return nil
+}
+
+func registerForm(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
+	if ctx.Session.Values["user"] != nil {
+		http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
+		return
+	}
+	return T("register.html").Execute(wri, map[string]interface{}{
+		"ctx": ctx,
+	})
+}
+
+func register(wri http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
+	req.ParseForm()
+	userData := new(UserForm)
+	schema.NewDecoder().Decode(userData, req.Form)
+	if userData.Password != userData.PasswordSecond {
+		ctx.Session.AddFlash("Passwords not match")
+		return registerForm(wri, req, ctx)
+	}
+
+	if userData.Password == "" {
+		ctx.Session.AddFlash("Password can't be empty")
+		return registerForm(wri, req, ctx)
+	}
+
+	user := &User{
+		Name: userData.Name,
+	}
+	user.SetPassword(userData.Password)
+
+	user.ID, err = createUser(user, ctx)
+	if err != nil {
+		ctx.Session.AddFlash("User with same name already exist")
+		return registerForm(wri, req, ctx)
+	}
+
+	ctx.Session.Values["user"] = user.ID
+	http.Redirect(wri, req, reverse("index"), http.StatusSeeOther)
+	return nil
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.