-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
494 additions
and
223 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"app_mode": "dev", | ||
"app_port": "8080", | ||
"app_log_level": "info", | ||
"app_domain": "example.com", | ||
"mysql_username": "root", | ||
"mysql_password": "root", | ||
"mysql_protocol": "tcp", | ||
"mysql_host": "localhost", | ||
"mysql_port": "3306", | ||
"mysql_database": "beaver" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2018 Clivern. All rights reserved. | ||
// Use of this source code is governed by the MIT | ||
// license that can be found in the LICENSE file. | ||
|
||
package controller | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// Channel | ||
func Channel(c *gin.Context) { | ||
appID := c.Param("app_id") | ||
channelName := c.Param("channel_name") | ||
|
||
c.JSON(200, gin.H{ | ||
"status": "ok", | ||
"appID": appID, | ||
"channelName": channelName, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2018 Clivern. All rights reserved. | ||
// Use of this source code is governed by the MIT | ||
// license that can be found in the LICENSE file. | ||
|
||
package controller | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// ChannelUsers | ||
func ChannelUsers(c *gin.Context) { | ||
appID := c.Param("app_id") | ||
channelName := c.Param("channel_name") | ||
|
||
c.JSON(200, gin.H{ | ||
"status": "ok", | ||
"appID": appID, | ||
"channelName": channelName, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2018 Clivern. All rights reserved. | ||
// Use of this source code is governed by the MIT | ||
// license that can be found in the LICENSE file. | ||
|
||
package controller | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// Channels | ||
func Channels(c *gin.Context) { | ||
appID := c.Param("app_id") | ||
|
||
c.JSON(200, gin.H{ | ||
"status": "ok", | ||
"appID": appID, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2018 Clivern. All rights reserved. | ||
// Use of this source code is governed by the MIT | ||
// license that can be found in the LICENSE file. | ||
|
||
package controller | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
|
||
"fmt" | ||
"github.com/gorilla/websocket" | ||
_ "log" | ||
"net/http" | ||
) | ||
|
||
var upgrader = websocket.Upgrader{ | ||
ReadBufferSize: 1024, | ||
WriteBufferSize: 1024, | ||
CheckOrigin: func(_ *http.Request) bool { | ||
return true | ||
}, | ||
} | ||
|
||
// Websocket | ||
func Websocket(c *gin.Context) { | ||
//key := c.Param("key") | ||
|
||
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil) | ||
defer func() { | ||
if conn != nil { | ||
conn.Close() | ||
} | ||
}() | ||
|
||
if err != nil { | ||
fmt.Println("1") | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
|
||
for { | ||
_, message, err := conn.ReadMessage() | ||
|
||
if err != nil { | ||
fmt.Println("2") | ||
fmt.Println(err.Error()) | ||
break | ||
} | ||
|
||
conn.WriteJSON(fmt.Sprintf(`{"item":"%s"}`, message)) | ||
fmt.Println(string(message)) | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2018 Clivern. All rights reserved. | ||
// Use of this source code is governed by the MIT | ||
// license that can be found in the LICENSE file. | ||
|
||
package driver | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"github.com/clivern/beaver/internal/pkg/logger" | ||
_ "github.com/go-sql-driver/mysql" | ||
) | ||
|
||
// MySQL | ||
type MySQL struct { | ||
Username string | ||
Password string | ||
Host string | ||
Port int | ||
Database string | ||
Protocol string | ||
} | ||
|
||
// Ping check the db connection | ||
func (e *MySQL) Ping() bool { | ||
|
||
db, err := sql.Open( | ||
"mysql", | ||
fmt.Sprintf("%s:%s@%s(%s:%d)/%s", e.Username, e.Password, e.Protocol, e.Host, e.Port, e.Database), | ||
) | ||
|
||
if err != nil { | ||
logger.Errorf("Error connecting to DB: %s", err.Error()) | ||
return false | ||
} | ||
|
||
defer db.Close() | ||
|
||
err = db.Ping() | ||
|
||
if err != nil { | ||
logger.Errorf("Error while checking DB connection: %s", err.Error()) | ||
return false | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.