Commit 662a51aa authored by Jisan Ahmed's avatar Jisan Ahmed
Browse files

Todo_with_orm added

parent a25c9f3e
package models
import (
"database/sql"
"fmt"
)
type Todo struct {
Id int
Name string
Done bool
}
type TodoModel struct {
DB *sql.DB
}
func (m *TodoModel) All() ([]*Todo, error) {
query := "SELECT Id,Name,Done FROM todos"
_, err := m.DB.Query(query)
if err != nil {
return nil, err
}
// return nil, nil
// defer rows.Close()
// var todos []*Todo
// for rows.Next() {
// todo := &Todo{}
// err := rows.Scan(&todo.Id, &todo.Name, &todo.Done)
// if err != nil {
// return nil, err
// }
// todos = append(todos, todo)
// }
// if err = rows.Err(); err != nil {
// return nil, err
// }
return nil, nil
}
func (m *TodoModel) Create(name string) (*Todo, error) {
if name == "" {
return nil, fmt.Errorf("name is required")
}
if m.DB == nil {
fmt.Println("Database connection is nil") // Debugging log
return nil, fmt.Errorf("database connection is nil")
}
query := "INSERT INTO todos (Name,Done) VALUES (?,?)"
result, err := m.DB.Exec(query, name, false)
if err != nil {
fmt.Printf("Error executing query: %v\n", err) // Debugging log
return nil, err
}
id, err := result.LastInsertId()
if err != nil {
fmt.Printf("Error getting last insert ID: %v\n", err) // Debugging log
return nil, err
}
return &Todo{
Id: int(id),
Name: name,
Done: false,
}, nil
}
func (m *TodoModel) Save(name string) error {
if name == "" {
return fmt.Errorf("name is required")
}
query := "INSERT INTO todos (Name,Done) VALUES (?,?)"
_, err := m.DB.Exec(query, name, false)
if err != nil {
return err
}
return nil
}
func (m *TodoModel) Find(id int) (*Todo, error) {
query := "SELECT Id,Name,Done FROM todos WHERE Id=?"
row := m.DB.QueryRow(query, id)
todo := &Todo{}
err := row.Scan(&todo.Id, &todo.Name, &todo.Done)
if err != nil {
if err == sql.ErrNoRows {
return nil, fmt.Errorf("todo not found")
}
return nil, err
}
return todo, nil
}
func (m *TodoModel) Update(id int, name string, done bool) error {
query := "UPDATE todos SET Name=?,Done=? WHERE Id=?"
_, err := m.DB.Exec(query, id, name, done)
if err != nil {
return err
}
return nil
}
func (m *TodoModel) Delete(id int) error {
query := "DELETE FROM todos WHERE Id=?"
_, err := m.DB.Exec(query, id)
if err != nil {
return err
}
return nil
}
package models
import (
"errors"
"strconv"
"time"
)
var (
Objects map[string]*Object
)
type Object struct {
ObjectId string
Score int64
PlayerName string
}
func init() {
Objects = make(map[string]*Object)
Objects["hjkhsbnmn123"] = &Object{"hjkhsbnmn123", 100, "astaxie"}
Objects["mjjkxsxsaa23"] = &Object{"mjjkxsxsaa23", 101, "someone"}
}
func AddOne(object Object) (ObjectId string) {
object.ObjectId = "astaxie" + strconv.FormatInt(time.Now().UnixNano(), 10)
Objects[object.ObjectId] = &object
return object.ObjectId
}
func GetOne(ObjectId string) (object *Object, err error) {
if v, ok := Objects[ObjectId]; ok {
return v, nil
}
return nil, errors.New("ObjectId Not Exist")
}
func GetAll() map[string]*Object {
return Objects
}
func Update(ObjectId string, Score int64) (err error) {
if v, ok := Objects[ObjectId]; ok {
v.Score = Score
return nil
}
return errors.New("ObjectId Not Exist")
}
func Delete(ObjectId string) {
delete(Objects, ObjectId)
}
package models
import (
"errors"
"strconv"
"time"
)
var (
UserList map[string]*User
)
func init() {
UserList = make(map[string]*User)
u := User{"user_11111", "astaxie", "11111", Profile{"male", 20, "Singapore", "astaxie@gmail.com"}}
UserList["user_11111"] = &u
}
type User struct {
Id string
Username string
Password string
Profile Profile
}
type Profile struct {
Gender string
Age int
Address string
Email string
}
func AddUser(u User) string {
u.Id = "user_" + strconv.FormatInt(time.Now().UnixNano(), 10)
UserList[u.Id] = &u
return u.Id
}
func GetUser(uid string) (u *User, err error) {
if u, ok := UserList[uid]; ok {
return u, nil
}
return nil, errors.New("User not exists")
}
func GetAllUsers() map[string]*User {
return UserList
}
func UpdateUser(uid string, uu *User) (a *User, err error) {
if u, ok := UserList[uid]; ok {
if uu.Username != "" {
u.Username = uu.Username
}
if uu.Password != "" {
u.Password = uu.Password
}
if uu.Profile.Age != 0 {
u.Profile.Age = uu.Profile.Age
}
if uu.Profile.Address != "" {
u.Profile.Address = uu.Profile.Address
}
if uu.Profile.Gender != "" {
u.Profile.Gender = uu.Profile.Gender
}
if uu.Profile.Email != "" {
u.Profile.Email = uu.Profile.Email
}
return u, nil
}
return nil, errors.New("User Not Exist")
}
func Login(username, password string) bool {
for _, u := range UserList {
if u.Username == username && u.Password == password {
return true
}
}
return false
}
func DeleteUser(uid string) {
delete(UserList, uid)
}
// @APIVersion 1.0.0
// @Title beego Test API
// @Description beego has a very cool tools to autogenerate documents for your API
// @Contact astaxie@gmail.com
// @TermsOfServiceUrl http://beego.me/
// @License Apache 2.0
// @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
package routers package routers
import ( import (
"Todo/controllers" "Todo/controllers"
beego "github.com/beego/beego/v2/server/web" "github.com/beego/beego/v2/server/web"
) )
func init() { // RegisterRoutes registers all routes for the application
ns := beego.NewNamespace("/v1", func RegisterRoutes(todoController *controllers.TodoController) {
beego.NSNamespace("/object", web.Router("/", todoController, "get:Index")
beego.NSInclude( web.Router("/api/todo", todoController, "get:ListTodos;post:NewTodo")
&controllers.ObjectController{}, web.Router("/api/todo/:id:int", todoController, "get:GetTodo;put:UpdateTodo")
), web.Router("/api/todo/delete/:id", todoController, "delete:DeleteTodo")
),
beego.NSNamespace("/user",
beego.NSInclude(
&controllers.UserController{},
),
),
)
beego.AddNamespace(ns)
} }
DB_USER=tl-g-developer
DB_PASSWORD=G33p33a55_dataChai
DB_HOST=103.199.168.130
DB_PORT=3716
DB_NAME=todo_app
appname = TodoWithORM
httpport = 8086
runmode = dev
autorender = false
copyrequestbody = true
EnableDocs = true
sqlconn = tl-g-developer:G33p33a55_dataChai@tcp(103.199.168.130:3306)/todo_app?charset=utf8&loc=Asia%2FDhaka
package controllers
import (
"TodoWithORM/models"
"encoding/json"
"strconv"
beego "github.com/beego/beego/v2/server/web"
)
type TodoController struct {
beego.Controller
model models.TodoModel
}
func (c *TodoController) OutputContext(status int, message string) {
c.Ctx.Output.SetStatus(status)
c.Ctx.Output.Body([]byte(message + "\n"))
}
func (this *TodoController) ListTodos() {
todos, err := this.model.All()
if err != nil {
this.OutputContext(500, "Failed to fetch todos")
return
}
this.Data["json"] = todos
this.ServeJSON()
}
func (c *TodoController) Index() {
c.Data["json"] = map[string]string{"message": "Welcome to Todo App"}
c.ServeJSON()
}
func (this *TodoController) NewTodo() {
req := struct{ Name string }{}
err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
if err != nil || req.Name == "" {
this.OutputContext(400, "Invalid request: empty name")
return
}
err = this.model.Save(req.Name)
if err != nil {
this.OutputContext(500, "Failed to create todo")
return
}
this.OutputContext(201, "Todo created successfully")
}
func (this *TodoController) GetTodo() {
ids := this.Ctx.Input.Param(":id")
id, err := strconv.Atoi(ids)
if err != nil {
this.OutputContext(400, "Invalid ID")
return
}
todo := this.model.Find(id)
if todo == nil {
this.OutputContext(404, "Todo not found")
return
}
this.Data["json"] = todo
this.ServeJSON()
}
func (this *TodoController) UpdateTodo() {
ids := this.Ctx.Input.Param(":id")
id, err := strconv.Atoi(ids)
if err != nil {
this.OutputContext(400, "Invalid ID")
return
}
req := struct {
Name string
Done string
}{}
err = json.Unmarshal(this.Ctx.Input.RequestBody, &req)
if err != nil {
this.OutputContext(400, "Invalid request: "+err.Error())
return
}
todo := this.model.Find(id)
if todo == nil {
this.OutputContext(404, "Todo not found")
return
}
if req.Name != "" {
todo.Name = req.Name
}
if req.Done == "true" {
todo.Done = true
} else if req.Done == "false" {
todo.Done = false
}
err = this.model.Update(id, todo.Name, todo.Done)
if err != nil {
this.OutputContext(500, "Failed to update todo")
return
}
this.OutputContext(200, "Todo updated successfully")
}
func (this *TodoController) DeleteTodo() {
ids := this.Ctx.Input.Param(":id")
id, err := strconv.Atoi(ids)
if err != nil {
this.OutputContext(400, "Invalid ID")
return
}
err = this.model.Delete(id)
if err != nil {
this.OutputContext(500, "Failed to delete todo")
return
}
this.OutputContext(200, "Todo deleted successfully")
}
2024/08/18 14:15:29.563 [I] [main.go:47] Logging configured successfully
2024/08/18 14:15:29.567 [I] [server.go:280] http server Running on http://:8079
2024/08/18 14:18:29.614 [I] [main.go:46] Logging configured successfully
2024/08/18 14:18:29.618 [I] [server.go:280] http server Running on http://:8079
2024/08/18 14:20:08.830 [I] [main.go:46] Logging configured successfully
2024/08/18 14:20:08.833 [I] [server.go:280] http server Running on http://:8079
2024/08/18 14:20:08.834 [C] [server.go:297] ListenAndServe: listen tcp :8079: bind: address already in use
2024/08/18 14:20:25.370 [I] [main.go:46] Logging configured successfully
2024/08/18 14:20:25.373 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:23:43.294 [I] [main.go:47] Logging configured successfully
2024/08/18 14:23:43.312 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:24:55.552 [I] [main.go:47] Logging configured successfully
2024/08/18 14:24:55.558 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:25:07.003 [I] [main.go:47] Logging configured successfully
2024/08/18 14:25:07.008 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:25:10.490 [I] [main.go:47] Logging configured successfully
2024/08/18 14:25:10.494 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:25:35.452 [I] [main.go:47] Logging configured successfully
2024/08/18 14:25:35.469 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:25:40.798 [I] [main.go:47] Logging configured successfully
2024/08/18 14:25:40.816 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:25:52.916 [I] [main.go:47] Logging configured successfully
2024/08/18 14:25:52.921 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:26:14.444 [I] [main.go:47] Logging configured successfully
2024/08/18 14:26:14.463 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:26:17.854 [I] [main.go:47] Logging configured successfully
2024/08/18 14:26:17.858 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:26:19.309 [I] [main.go:47] Logging configured successfully
2024/08/18 14:26:19.313 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:26:20.825 [I] [main.go:47] Logging configured successfully
2024/08/18 14:26:20.831 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:26:33.439 [I] [main.go:47] Logging configured successfully
2024/08/18 14:26:33.444 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:26:47.035 [I] [main.go:47] Logging configured successfully
2024/08/18 14:26:47.044 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:26:48.081 [I] [main.go:47] Logging configured successfully
2024/08/18 14:26:48.085 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:27:16.579 [I] [main.go:47] Logging configured successfully
2024/08/18 14:27:16.602 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:27:26.068 [I] [main.go:47] Logging configured successfully
2024/08/18 14:27:26.073 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:27:33.050 [I] [main.go:47] Logging configured successfully
2024/08/18 14:27:33.055 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:27:39.481 [I] [main.go:47] Logging configured successfully
2024/08/18 14:27:39.484 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:27:51.016 [I] [main.go:47] Logging configured successfully
2024/08/18 14:27:51.020 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:27:57.334 [I] [main.go:47] Logging configured successfully
2024/08/18 14:27:57.340 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:28:07.538 [I] [main.go:47] Logging configured successfully
2024/08/18 14:28:07.543 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:28:14.257 [I] [main.go:47] Logging configured successfully
2024/08/18 14:28:14.263 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:28:19.700 [I] [main.go:47] Logging configured successfully
2024/08/18 14:28:19.704 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:28:22.704 [I] [main.go:47] Logging configured successfully
2024/08/18 14:28:22.724 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:28:43.357 [I] [main.go:47] Logging configured successfully
2024/08/18 14:28:43.376 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:28:50.357 [I] [main.go:47] Logging configured successfully
2024/08/18 14:28:50.365 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:29:03.124 [I] [main.go:47] Logging configured successfully
2024/08/18 14:29:03.132 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:29:06.787 [I] [main.go:47] Logging configured successfully
2024/08/18 14:29:06.791 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:29:08.604 [I] [main.go:47] Logging configured successfully
2024/08/18 14:29:08.618 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:29:13.972 [I] [main.go:47] Logging configured successfully
2024/08/18 14:29:13.991 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:29:16.178 [I] [main.go:47] Logging configured successfully
2024/08/18 14:29:16.182 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:29:22.222 [I] [main.go:47] Logging configured successfully
2024/08/18 14:29:22.230 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:29:27.562 [I] [main.go:47] Logging configured successfully
2024/08/18 14:29:27.569 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:29:32.573 [I] [main.go:47] Logging configured successfully
2024/08/18 14:29:32.577 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:29:41.501 [I] [main.go:47] Logging configured successfully
2024/08/18 14:29:41.505 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:29:49.887 [I] [main.go:47] Logging configured successfully
2024/08/18 14:29:49.901 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:30:12.949 [I] [main.go:47] Logging configured successfully
2024/08/18 14:30:12.952 [I] [server.go:280] http server Running on http://:8082
2024/08/18 14:30:12.953 [C] [server.go:297] ListenAndServe: listen tcp :8082: bind: address already in use
2024/08/18 14:30:27.712 [I] [main.go:47] Logging configured successfully
2024/08/18 14:30:27.718 [I] [server.go:280] http server Running on http://:8083
2024/08/18 14:30:58.381 [D] [router.go:1306] | ::1| 404 | 154.719µs| nomatch| GET  /
2024/08/18 14:31:25.202 [D] [router.go:1306] | ::1| 404 | 92.8µs| nomatch| GET  /
2024/08/18 14:31:44.670 [D] [router.go:1306] | ::1| 404 | 88.318µs| nomatch| GET  /api/todo
2024/08/18 14:32:51.499 [I] [main.go:47] Logging configured successfully
2024/08/18 14:32:51.505 [I] [server.go:280] http server Running on http://:8083
2024/08/18 14:35:27.206 [I] [main.go:47] Logging configured successfully
2024/08/18 14:35:27.223 [I] [server.go:280] http server Running on http://:8083
2024/08/18 14:35:27.224 [C] [server.go:297] ListenAndServe: listen tcp :8083: bind: address already in use
2024/08/18 14:35:45.082 [I] [main.go:47] Logging configured successfully
2024/08/18 14:35:45.086 [I] [server.go:280] http server Running on http://:8084
2024/08/18 14:36:21.036 [I] [main.go:46] Logging configured successfully
2024/08/18 14:36:21.043 [I] [server.go:280] http server Running on http://:8084
2024/08/18 14:36:43.678 [I] [main.go:46] Logging configured successfully
2024/08/18 14:36:43.683 [I] [server.go:280] http server Running on http://:8084
2024/08/18 14:36:43.684 [C] [server.go:297] ListenAndServe: listen tcp :8084: bind: address already in use
2024/08/18 14:37:36.588 [I] [main.go:47] Logging configured successfully
2024/08/18 14:37:36.594 [I] [server.go:280] http server Running on http://:8084
2024/08/18 14:37:36.595 [C] [server.go:297] ListenAndServe: listen tcp :8084: bind: address already in use
2024/08/18 14:37:51.586 [I] [main.go:47] Logging configured successfully
2024/08/18 14:37:51.590 [I] [server.go:280] http server Running on http://:8084
2024/08/18 14:37:51.590 [C] [server.go:297] ListenAndServe: listen tcp :8084: bind: address already in use
2024/08/18 14:38:25.292 [I] [main.go:47] Logging configured successfully
2024/08/18 14:38:25.312 [I] [server.go:280] http server Running on http://:8084
2024/08/18 14:38:25.313 [C] [server.go:297] ListenAndServe: listen tcp :8084: bind: address already in use
2024/08/18 14:38:43.869 [I] [main.go:47] Logging configured successfully
2024/08/18 14:38:43.872 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:40:43.295 [D] [router.go:1306] | ::1| 404 | 124.635µs| nomatch| GET  /
2024/08/18 14:42:34.772 [I] [main.go:47] Logging configured successfully
2024/08/18 14:42:34.783 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:42:49.048 [I] [main.go:47] Logging configured successfully
2024/08/18 14:42:49.052 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:43:03.869 [I] [main.go:47] Logging configured successfully
2024/08/18 14:43:03.876 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:43:15.495 [I] [main.go:47] Logging configured successfully
2024/08/18 14:43:15.499 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:43:19.658 [I] [main.go:47] Logging configured successfully
2024/08/18 14:43:19.674 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:43:39.931 [I] [main.go:47] Logging configured successfully
2024/08/18 14:43:39.950 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:43:41.495 [I] [main.go:47] Logging configured successfully
2024/08/18 14:43:41.499 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:43:49.244 [I] [main.go:47] Logging configured successfully
2024/08/18 14:43:49.251 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:45:09.839 [I] [main.go:47] Logging configured successfully
2024/08/18 14:45:09.843 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:45:11.763 [I] [main.go:47] Logging configured successfully
2024/08/18 14:45:11.767 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:45:17.045 [I] [main.go:47] Logging configured successfully
2024/08/18 14:45:17.050 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:45:25.723 [I] [main.go:47] Logging configured successfully
2024/08/18 14:45:25.727 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:47:05.798 [I] [main.go:47] Logging configured successfully
2024/08/18 14:47:05.816 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:47:11.957 [I] [main.go:47] Logging configured successfully
2024/08/18 14:47:11.961 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:47:14.844 [I] [main.go:47] Logging configured successfully
2024/08/18 14:47:14.850 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:47:23.626 [D] [router.go:1306] | ::1| 404 | 139.136µs| nomatch| GET  /
2024/08/18 14:49:59.511 [I] [main.go:47] Logging configured successfully
2024/08/18 14:49:59.516 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:50:03.099 [I] [main.go:47] Logging configured successfully
2024/08/18 14:50:03.103 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:50:05.088 [I] [main.go:47] Logging configured successfully
2024/08/18 14:50:05.096 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:50:42.459 [D] [router.go:1306] | ::1| 404 | 137.073µs| nomatch| GET  /
2024/08/18 14:51:17.958 [I] [main.go:47] Logging configured successfully
2024/08/18 14:51:17.964 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:51:20.838 [I] [main.go:47] Logging configured successfully
2024/08/18 14:51:20.842 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:51:27.491 [I] [main.go:47] Logging configured successfully
2024/08/18 14:51:27.510 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:51:29.897 [I] [main.go:47] Logging configured successfully
2024/08/18 14:51:29.901 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:51:31.321 [D] [router.go:1306] | ::1| 404 | 148.472µs| nomatch| GET  /
2024/08/18 14:55:00.688 [D] [router.go:1306] | ::1| 404 | 114.753µs| nomatch| GET  /
2024/08/18 14:59:36.585 [I] [main.go:50] Logging configured successfully
2024/08/18 14:59:36.593 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:59:40.253 [I] [main.go:50] Logging configured successfully
2024/08/18 14:59:40.258 [I] [server.go:280] http server Running on http://:8085
2024/08/18 14:59:41.966 [I] [main.go:50] Logging configured successfully
2024/08/18 14:59:41.971 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:00:48.429 [I] [main.go:50] Logging configured successfully
2024/08/18 15:00:48.433 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:01:24.790 [I] [main.go:50] Logging configured successfully
2024/08/18 15:01:24.811 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:01:36.448 [I] [main.go:50] Logging configured successfully
2024/08/18 15:01:36.453 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:01:55.524 [I] [main.go:50] Logging configured successfully
2024/08/18 15:01:55.543 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:02:02.308 [I] [main.go:50] Logging configured successfully
2024/08/18 15:02:02.313 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:02:11.526 [I] [main.go:50] Logging configured successfully
2024/08/18 15:02:11.530 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:02:17.557 [I] [main.go:50] Logging configured successfully
2024/08/18 15:02:17.560 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:02:19.787 [D] [router.go:1306] | ::1| 404 | 127.186µs| nomatch| GET  /
2024/08/18 15:02:35.619 [I] [main.go:50] Logging configured successfully
2024/08/18 15:02:35.623 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:04:53.549 [D] [router.go:1306] | ::1| 404 | 146.493µs| nomatch| GET  /
2024/08/18 15:05:09.715 [I] [main.go:50] Logging configured successfully
2024/08/18 15:05:09.719 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:05:13.514 [D] [router.go:1306] | ::1| 404 | 133.977µs| nomatch| GET  /
2024/08/18 15:06:59.119 [I] [main.go:50] Logging configured successfully
2024/08/18 15:06:59.127 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:07:00.293 [I] [main.go:50] Logging configured successfully
2024/08/18 15:07:00.313 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:07:19.682 [I] [main.go:50] Logging configured successfully
2024/08/18 15:07:19.687 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:07:23.318 [I] [main.go:50] Logging configured successfully
2024/08/18 15:07:23.334 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:07:45.312 [I] [main.go:51] Logging configured successfully
2024/08/18 15:07:45.324 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:07:47.190 [I] [main.go:51] Logging configured successfully
2024/08/18 15:07:47.199 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:07:49.234 [I] [main.go:50] Logging configured successfully
2024/08/18 15:07:49.239 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:07:51.858 [D] [router.go:1306] | ::1| 200 | 38.395µs| match| GET  / r:/
2024/08/18 15:08:58.370 [I] [main.go:50] Logging configured successfully
2024/08/18 15:08:58.388 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:09:12.587 [I] [main.go:50] Logging configured successfully
2024/08/18 15:09:12.604 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:11:23.325 [I] [main.go:50] Logging configured successfully
2024/08/18 15:11:23.344 [I] [server.go:280] http server Running on http://:8085
2024/08/18 15:11:23.344 [C] [server.go:297] ListenAndServe: listen tcp :8085: bind: address already in use
2024/08/18 15:11:45.596 [I] [main.go:50] Logging configured successfully
2024/08/18 15:11:45.607 [I] [server.go:280] http server Running on http://:8086
2024/08/18 15:12:33.683 [I] [main.go:50] Logging configured successfully
2024/08/18 15:12:33.689 [I] [server.go:280] http server Running on http://:8086
2024/08/18 15:12:35.243 [I] [main.go:50] Logging configured successfully
2024/08/18 15:12:35.247 [I] [server.go:280] http server Running on http://:8086
2024/08/18 15:14:36.960 [I] [main.go:52] Logging configured successfully
2024/08/18 15:14:36.983 [I] [server.go:280] http server Running on http://:8086
2024/08/18 15:14:40.033 [I] [main.go:50] Logging configured successfully
2024/08/18 15:14:40.037 [I] [server.go:280] http server Running on http://:8086
2024/08/18 15:14:41.785 [I] [main.go:50] Logging configured successfully
2024/08/18 15:14:41.805 [I] [server.go:280] http server Running on http://:8086
2024/08/18 15:17:33.921 [D] [router.go:1306] | ::1| 500 | 18.494558ms| match| POST  /api/todo r:/api/todo
2024/08/18 15:24:29.487 [I] [main.go:50] Logging configured successfully
2024/08/18 15:24:29.491 [I] [server.go:280] http server Running on http://:8086
2024/08/18 15:25:27.872 [I] [main.go:50] Logging configured successfully
2024/08/18 15:25:27.876 [I] [server.go:280] http server Running on http://:8086
2024/08/18 15:25:43.259 [I] [main.go:50] Logging configured successfully
2024/08/18 15:25:43.262 [I] [server.go:280] http server Running on http://:8086
2024/08/18 15:32:32.639 [D] [router.go:1306] | ::1| 201 | 45.850854ms| match| POST  /api/todo r:/api/todo
2024/08/18 15:33:27.254 [D] [router.go:1306] | ::1| 201 | 50.287242ms| match| POST  /api/todo r:/api/todo
2024/08/18 15:33:58.714 [D] [router.go:1306] | ::1| 200 | 8.682805ms| match| GET  /api/todo r:/api/todo
2024/08/18 15:34:28.640 [D] [router.go:1306] | ::1| 200 | 46.838µs| match| GET  / r:/
2024/08/18 15:34:40.779 [D] [router.go:1306] | ::1| 200 | 3.646019ms| match| GET  /api/todo r:/api/todo
2024/08/18 15:36:40.356 [D] [router.go:1306] | ::1| 200 | 7.641973ms| match| GET  /api/todo/1 r:/api/todo/:id:int
2024/08/18 15:37:12.839 [D] [router.go:1306] | ::1| 404 | 112.815µs| nomatch| DELETE  /api/todo/1
2024/08/18 15:37:32.722 [D] [router.go:1306] | ::1| 200 | 46.575µs| match| GET  / r:/
2024/08/18 15:37:36.872 [D] [router.go:1306] | ::1| 200 | 3.127908ms| match| GET  /api/todo r:/api/todo
2024/08/18 15:38:01.659 [D] [router.go:1306] | ::1| 404 | 107.572µs| nomatch| DELETE  /todo/1
2024/08/18 15:38:08.390 [D] [router.go:1306] | ::1| 404 | 187.023µs| nomatch| DELETE  /todo/2
2024/08/18 15:38:37.996 [D] [router.go:1306] | ::1| 200 | 77.841369ms| match| DELETE  /api/todo/delete/2 r:/api/todo/delete/:id
2024/08/18 15:40:55.078 [D] [router.go:1306] | ::1| 200 | 36.142µs| match| GET  / r:/
2024/08/18 15:40:59.653 [D] [router.go:1306] | ::1| 200 | 3.697009ms| match| GET  /api/todo r:/api/todo
2024/08/18 15:46:28.217 [D] [router.go:1306] | ::1| 404 | 129.548µs| nomatch| PUT  /api/todo
2024/08/18 15:48:16.675 [D] [router.go:1306] | ::1| 200 | 58.970974ms| match| PUT  /api/todo/1 r:/api/todo/:id:int
2024/08/18 15:58:56.097 [I] [main.go:50] Logging configured successfully
2024/08/18 15:58:56.102 [I] [server.go:280] http server Running on http://:8086
2024/08/18 15:59:00.085 [I] [main.go:50] Logging configured successfully
2024/08/18 15:59:00.088 [I] [server.go:280] http server Running on http://:8086
module TodoWithORM
go 1.22
require github.com/beego/beego/v2 v2.3.0
require github.com/smartystreets/goconvey v1.6.4
require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
)
require (
github.com/beego/beego v1.12.13
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/go-sql-driver/mysql v1.8.1
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/joho/godotenv v1.5.1
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+DxYx+6BMjkBbe5ONFIF1MXffk=
github.com/beego/beego v1.12.13 h1:g39O1LGLTiPejWVqQKK/TFGrroW9BCZQz6/pf4S8IRM=
github.com/beego/beego v1.12.13/go.mod h1:QURFL1HldOcCZAxnc1cZ7wrplsYR5dKPHFjmk6WkLAs=
github.com/beego/beego/v2 v2.3.0 h1:iECVwzm6egw6iw6tkWrEDqXG4NQtKLQ6QBSYqlM6T/I=
github.com/beego/beego/v2 v2.3.0/go.mod h1:Ob/5BJ9fIKZLd4s9ZV3o9J6odkkIyL83et+p98gyYXo=
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
github.com/couchbase/go-couchbase v0.0.0-20201216133707-c04035124b17/go.mod h1:+/bddYDxXsf9qt0xpDUtRR47A2GjaXmGGAqQ/k3GJ8A=
github.com/couchbase/gomemcached v0.1.2-0.20201224031647-c432ccf49f32/go.mod h1:mxliKQxOv84gQ0bJWbI+w9Wxdpt9HjDvgW9MjCym5Vo=
github.com/couchbase/goutils v0.0.0-20210118111533-e33d3ffb5401/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs=
github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/glendc/gopher-json v0.0.0-20170414221815-dc4743023d0c/go.mod h1:Gja1A+xZ9BoviGJNA2E9vFkPjjsl+CoJxSXiQM1UXtw=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/ledisdb/ledisdb v0.0.0-20200510135210-d35789ec47e6/go.mod h1:n931TsDuKuq+uX4v1fulaMbA/7ZLLhjc85h7chZGBCQ=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterh/liner v1.0.1-0.20171122030339-3681c2a91233/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.0/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 h1:DAYUYH5869yV94zvCES9F51oYtN5oGlwjxJJz7ZCnik=
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
github.com/siddontang/goredis v0.0.0-20150324035039-760763f78400/go.mod h1:DDcKzU3qCuvj/tPnimWSsZZzvk9qvkvrIL5naVBPh5s=
github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/wendal/errors v0.0.0-20181209125328-7f31f4b264ec/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
github.com/yuin/gopher-lua v0.0.0-20171031051903-609c9cd26973/go.mod h1:aEV29XrmTYFr3CiRxZeGHpkvbwq+prZduBqMaascyCU=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
package main
import (
_ "TodoWithORM/routers"
"log"
"github.com/beego/beego/orm"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web"
_ "github.com/go-sql-driver/mysql"
)
// dbConnection establishes a connection to the database.
func dbConnection() {
sqlconn, err := web.AppConfig.String("sqlconn")
if err != nil {
logs.Error("Failed to retrieve SQL connection string from config: %v", err)
log.Fatal(err)
return
}
err = orm.RegisterDataBase("default", "mysql", sqlconn)
if err != nil {
logs.Error("Failed to register database: %v", err)
return
}
logs.Info("Database connection established successfully")
}
// init initializes the database connection and logging settings.
func init() {
logs.Info("Starting database connection setup...")
err := orm.RegisterDriver("mysql", orm.DRMySQL)
if err != nil {
logs.Error("Failed to register MySQL driver: %v", err)
return
}
dbConnection()
// Configure logging
logConfig := `{"filename":"error.log","perm":"777","level":7,"maxlines":0,"maxsize":0,"daily":true,"maxdays":10,"color":true}`
err = logs.SetLogger(logs.AdapterFile, logConfig)
if err != nil {
logs.Error("Failed to configure logging: %v", err)
return
}
logs.Info("Logging configured successfully")
}
func main() {
web.Run()
}
package models
import (
"fmt"
"github.com/beego/beego/orm"
)
type Todo struct {
Id int
Name string
Done bool
}
type TodoModel struct {
}
func init() {
orm.RegisterModel(new(Todo))
}
func (c *TodoModel) All() ([]*Todo, error) {
o := orm.NewOrm()
var todos []*Todo
_, err := o.QueryTable("todo").All(&todos)
return todos, err
}
func (c *TodoModel) Save(name string) error {
if name == "" {
return fmt.Errorf("empty name\n")
}
o := orm.NewOrm()
todo := new(Todo)
todo.Name = name
_, err := o.Insert(todo)
return err
}
func (c *TodoModel) Find(id int) *Todo {
o := orm.NewOrm()
todo := Todo{Id: id}
err := o.Read(&todo)
if err != nil {
return nil
}
return &todo
}
func (c *TodoModel) Update(id int, name string, done bool) error {
o := orm.NewOrm()
todo := c.Find(id)
if todo == nil {
return fmt.Errorf("not found todo")
}
todo.Name = name
todo.Done = done
_, err := o.Update(todo)
if err != nil {
return err
}
return nil
}
func (c *TodoModel) Delete(id int) error {
o := orm.NewOrm()
todo := c.Find(id)
if todo == nil {
return fmt.Errorf("not found todo")
}
_, err := o.Delete(todo)
return err
}
package routers
import (
"TodoWithORM/controllers"
beego "github.com/beego/beego/v2/server/web"
)
// RegisterRoutes registers all routes for the application
func init() {
beego.Router("/", &controllers.TodoController{}, "get:Index")
beego.Router("/api/todo", &controllers.TodoController{}, "get:ListTodos;post:NewTodo")
beego.Router("/api/todo/:id:int", &controllers.TodoController{}, "get:GetTodo;put:UpdateTodo")
beego.Router("/api/todo/delete/:id", &controllers.TodoController{}, "delete:DeleteTodo")
}
package test
import (
"net/http"
"net/http/httptest"
"testing"
"runtime"
"path/filepath"
_ "TodoWithORM/routers"
beego "github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/core/logs"
. "github.com/smartystreets/goconvey/convey"
)
func init() {
_, file, _, _ := runtime.Caller(0)
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator))))
beego.TestBeegoInit(apppath)
}
// TestGet is a sample to run an endpoint test
func TestGet(t *testing.T) {
r, _ := http.NewRequest("GET", "/v1/object", nil)
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
logs.Info("testing", "TestGet", "Code[%d]\n%s", w.Code, w.Body.String())
Convey("Subject: Test Station Endpoint\n", t, func() {
Convey("Status Code Should Be 200", func() {
So(w.Code, ShouldEqual, 200)
})
Convey("The Result Should Not Be Empty", func() {
So(w.Body.Len(), ShouldBeGreaterThan, 0)
})
})
}
module TodoWithOrm
go 1.22.6
require github.com/beego/beego/v2 v2.3.0 // indirect
github.com/beego/beego/v2 v2.3.0 h1:iECVwzm6egw6iw6tkWrEDqXG4NQtKLQ6QBSYqlM6T/I=
github.com/beego/beego/v2 v2.3.0/go.mod h1:Ob/5BJ9fIKZLd4s9ZV3o9J6odkkIyL83et+p98gyYXo=
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment