Skip to content

Commit

Permalink
iris v12.2.0-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Sep 13, 2020
1 parent 4de6d8e commit 16344c8
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 198 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.vscode
.vscode
go.sum
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ This is a fork of: https://github.com/yTakkar/Go-Mini-Social-Network.
Created by [@kataras](https://twitter.com/MakisMaropoulos) as an example on converting a web app from gin to iris. The structure is the same as the original repository, nothing changed in order to be easier to watch the changes between them.

# Quick Links

1. [Screenshots](#screenshots)
2. [Requirements](#requirements)
3. [Usage](#usage)

# Screenshots

![alt text](https://raw.githubusercontent.com/iris-contrib/Iris-Mini-Social-Network/master/screenshots/Snap%202017-09-26%20at%2001.11.55.png)
![alt text](https://raw.githubusercontent.com/iris-contrib/Iris-Mini-Social-Network/master/screenshots/Snap%202017-09-26%20at%2001.12.18.png)
![alt text](https://raw.githubusercontent.com/iris-contrib/Iris-Mini-Social-Network/master/screenshots/Snap%202017-09-26%20at%2013.11.39.png)
Expand All @@ -20,9 +22,10 @@ Created by [@kataras](https://twitter.com/MakisMaropoulos) as an example on conv
![alt text](https://raw.githubusercontent.com/iris-contrib/Iris-Mini-Social-Network/master/screenshots/Snap%202017-09-26%20at%2001.13.29.png)

# Requirements
1. Make sure you keep this project inside `src/` of your Golang project folder ($GOPATH).

1. Make sure you have installed [Go](https://golang.org) and [Iris](https://github.com/kataras/iris).
2. Following packages should be installed.
1. [iris](https://github.com/kataras/iris)
1. [Iris](https://github.com/kataras/iris)
2. [checkmail](https://github.com/badoux/checkmail)
3. [MySQL driver](https://github.com/go-sql-driver/mysql)
4. [bcrypt](https://golang.org/x/crypto/bcrypt)
Expand All @@ -31,9 +34,10 @@ Created by [@kataras](https://twitter.com/MakisMaropoulos) as an example on conv

# Usage

1. Open PHPMyAdmin or any other db tool, create a db & import `db.sql`.
1. Create a MySQL database & import the `db.sql` file.

2. Install all the dependencies:

2. Install all the dependencies.
```bash
# with npm
npm install
Expand All @@ -42,7 +46,7 @@ npm install
yarn
```

3. Create a `.env` file & insert the following code. Replace values with yours!!
3. Create a `.env` file & insert the following code. Replace values with yours!
```javascript
PORT=YOUR PORT [STRING]
SESSION_HASH_SECRET=SESSION_HASH_KEY [STRING]
Expand Down
5 changes: 2 additions & 3 deletions config/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ func init() {
var secureCookie = securecookie.New(hashKey, blockKey)

manager = sessions.New(sessions.Config{
Cookie: "session_id",
Encode: secureCookie.Encode,
Decode: secureCookie.Decode,
Cookie: "session_id",
Encoding: secureCookie,
})

// println("hashKey = " + string(hashKey))
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Iris-Mini-Social-Network

go 1.13
go 1.15

require (
github.com/badoux/checkmail v0.0.0-20181210160741-9661bd69e9ad
github.com/go-sql-driver/mysql v1.4.1
github.com/gorilla/securecookie v1.1.1
github.com/joho/godotenv v1.3.0
github.com/kataras/iris/v12 v12.0.1
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
github.com/kataras/iris/v12 v12.2.0-alpha
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
)
133 changes: 0 additions & 133 deletions go.sum

This file was deleted.

15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (

func main() {
app := iris.New()
app.Use(recover.New())
app.UseRouter(recover.New())

app.RegisterView(iris.HTML("./views", ".html"))
app.HandleDir("/", "./public")
app.HandleDir("/", iris.Dir("./public"))

user := app.Party("/user")
{
Expand Down Expand Up @@ -64,5 +64,14 @@ func main() {
api.Post("/deactivate-account", R.DeactivateAcc)
}

app.Run(iris.Addr(os.Getenv("PORT")))
addr := ":8080"
if port := os.Getenv("PORT"); port != "" {
if port[0] != ':' {
port = ":" + port
}

addr = port
}

app.Listen(addr)
}
28 changes: 14 additions & 14 deletions routes/api_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ func CreateNewPost(ctx iris.Context) {

insertID, _ := rs.LastInsertId()

resp := map[string]interface{}{
resp := iris.Map{
"postID": insertID,
"mssg": "Post Created!!",
}
json(ctx, resp)
ctx.JSON(resp)
}

// DeletePost route
Expand All @@ -39,7 +39,7 @@ func DeletePost(ctx iris.Context) {
_, dErr := db.Exec("DELETE FROM posts WHERE postID=?", post)
CO.Err(dErr)

json(ctx, map[string]interface{}{
ctx.JSON(iris.Map{
"mssg": "Post Deleted!!",
})
}
Expand All @@ -53,14 +53,14 @@ func UpdatePost(ctx iris.Context) {
db := CO.DB()
db.Exec("UPDATE posts SET title=?, content=? WHERE postID=?", title, content, postID)

json(ctx, map[string]interface{}{
ctx.JSON(iris.Map{
"mssg": "Post Updated!!",
})
}

// UpdateProfile route
func UpdateProfile(ctx iris.Context) {
resp := make(map[string]interface{})
resp := make(iris.Map)

id, _ := CO.AllSessions(ctx)
username := ctx.PostValueTrim("username")
Expand All @@ -85,12 +85,12 @@ func UpdateProfile(ctx iris.Context) {
resp["success"] = true
}

json(ctx, resp)
ctx.JSON(resp)
}

// ChangeAvatar route
func ChangeAvatar(ctx iris.Context) {
resp := make(map[string]interface{})
resp := make(iris.Map)
id, _ := CO.AllSessions(ctx)

dir, _ := os.Getwd()
Expand All @@ -101,7 +101,7 @@ func ChangeAvatar(ctx iris.Context) {

// avatar key of post form file, but let's grab all of them,
// the `ctx.FormFile` can be used to manually upload files per post key to the server.
_, upErr := ctx.UploadFormFiles(dest)
_, _, upErr := ctx.UploadFormFiles(dest)

if upErr != nil {
resp["mssg"] = "An error occured!!"
Expand All @@ -110,7 +110,7 @@ func ChangeAvatar(ctx iris.Context) {
resp["success"] = true
}

json(ctx, resp)
ctx.JSON(resp)
}

// Follow route
Expand All @@ -124,7 +124,7 @@ func Follow(ctx iris.Context) {
_, exErr := stmt.Exec(id, user, time.Now())
CO.Err(exErr)

json(ctx, iris.Map{
ctx.JSON(iris.Map{
"mssg": "Followed " + username + "!!",
})
}
Expand All @@ -140,7 +140,7 @@ func Unfollow(ctx iris.Context) {
_, dErr := stmt.Exec(id, user)
CO.Err(dErr)

json(ctx, iris.Map{
ctx.JSON(iris.Map{
"mssg": "Unfollowed " + username + "!!",
})
}
Expand All @@ -155,7 +155,7 @@ func Like(ctx iris.Context) {
_, err := stmt.Exec(post, id, time.Now())
CO.Err(err)

json(ctx, iris.Map{
ctx.JSON(iris.Map{
"mssg": "Post Liked!!",
})
}
Expand All @@ -170,7 +170,7 @@ func Unlike(ctx iris.Context) {
_, err := stmt.Exec(post, id)
CO.Err(err)

json(ctx, iris.Map{
ctx.JSON(iris.Map{
"mssg": "Post Unliked!!",
})
}
Expand Down Expand Up @@ -208,7 +208,7 @@ func DeactivateAcc(ctx iris.Context) {
// or
session.Destroy()

json(ctx, iris.Map{
ctx.JSON(iris.Map{
"mssg": "Deactivated your account!!",
})
}
Loading

0 comments on commit 16344c8

Please sign in to comment.