-
Notifications
You must be signed in to change notification settings - Fork 0
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
15 changed files
with
804 additions
and
83 deletions.
There are no files selected for viewing
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,31 @@ | ||
package dao | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/jackc/pgx/v4" | ||
) | ||
|
||
const ( | ||
host = "localhost" | ||
port = 5432 | ||
user = "postgres" | ||
password = "021020" | ||
dbname = "chatroom" | ||
) | ||
|
||
var dbConn *pgx.Conn | ||
|
||
func ConnDB() *pgx.Conn { | ||
var err error | ||
dbConnParam := fmt.Sprintf(`%s://%s:%s@%s:%d/%s`, user, user, password, host, port, dbname) | ||
dbConn, err = pgx.Connect(context.Background(), dbConnParam) | ||
if err != nil { | ||
fmt.Println("failed to connect database") | ||
//panic(err.Error()) | ||
return nil | ||
} else { | ||
fmt.Println("connect database successfully") | ||
} | ||
return dbConn | ||
} |
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
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 |
---|---|---|
@@ -1,37 +1,34 @@ | ||
package reply_msg | ||
|
||
import ( | ||
"chatroom/cmn" | ||
"chatroom/serve" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
//annotation:reply_msg-service | ||
//author:{"name":"reply_msg","tel":"15521212871","email":"[email protected]"} | ||
//func Enroll(author string) { | ||
// var developer *cmn.ModuleAuthor | ||
// | ||
// if author != "" { | ||
// var d cmn.ModuleAuthor | ||
// err := json.Unmarshal([]byte(author), &d) | ||
// if err != nil { | ||
// return | ||
// } | ||
// developer = &d | ||
// } | ||
// | ||
// cmn.AddService(&cmn.ServeEndPoint{ | ||
// Fn: Response, | ||
// | ||
// Path: "/reply_msg", | ||
// Name: "reply_msg", | ||
// | ||
// Developer: developer, | ||
// }) | ||
//} | ||
|
||
func Enroll(author string) { | ||
var developer *cmn.ModuleAuthor | ||
|
||
if author != "" { | ||
var d cmn.ModuleAuthor | ||
err := json.Unmarshal([]byte(author), &d) | ||
if err != nil { | ||
return | ||
} | ||
developer = &d | ||
} | ||
|
||
cmn.AddService(&cmn.ServeEndPoint{ | ||
//Fn: user, | ||
|
||
Path: "/reply_msg", | ||
Name: "reply_msg", | ||
|
||
Developer: developer, | ||
}) | ||
} | ||
func Response(w http.ResponseWriter, msg *serve.ReplyMsg) { | ||
buf, err := json.Marshal(&msg) | ||
if err != nil { | ||
|
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,35 @@ | ||
package test | ||
|
||
import ( | ||
"chatroom/cmn" | ||
"encoding/json" | ||
"github.com/jackc/pgx/v4" | ||
"net/http" | ||
) | ||
|
||
//annotation:user_management-service | ||
//author:{"name":"user_management","tel":"15521212871","email":"[email protected]"} | ||
func Enroll(author string) { | ||
var developer *cmn.ModuleAuthor | ||
|
||
if author != "" { | ||
var d cmn.ModuleAuthor | ||
err := json.Unmarshal([]byte(author), &d) | ||
if err != nil { | ||
return | ||
} | ||
developer = &d | ||
} | ||
|
||
cmn.AddService(&cmn.ServeEndPoint{ | ||
Fn: test, | ||
|
||
Path: "/test", | ||
Name: "test", | ||
|
||
Developer: developer, | ||
}) | ||
} | ||
func test(w http.ResponseWriter, r *http.Request, dbConn *pgx.Conn) { | ||
println("hello") | ||
} |
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.