-
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.
feat: added json file to simulate db
- Loading branch information
Showing
14 changed files
with
183 additions
and
123 deletions.
There are no files selected for viewing
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 @@ | ||
[] - Check contenu json |
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 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
func AuthController(c *gin.Context) { | ||
c.JSON(http.StatusOK, gin.H{ | ||
"message": "do ypu really wanna authenticate", | ||
}) | ||
} |
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,14 @@ | ||
{ | ||
"todos" : [ | ||
{ | ||
"id": 1, | ||
"title": "Buy sushi's", | ||
"description": "go the market to get sushi's" | ||
}, | ||
{ | ||
"id": 2, | ||
"title": "Get the newest macbook", | ||
"description": "first get money and ten we'll see" | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -1,32 +1,33 @@ | ||
module post-go | ||
module bective | ||
|
||
go 1.21.0 | ||
|
||
require github.com/gin-gonic/gin v1.9.1 | ||
|
||
require ( | ||
github.com/bytedance/sonic v1.10.2 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect | ||
github.com/chenzhuoyu/iasm v0.9.0 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect | ||
github.com/bytedance/sonic v1.9.1 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/gin-gonic/gin v1.9.1 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.15.5 // indirect | ||
github.com/go-playground/validator/v10 v10.14.0 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/gorilla/mux v1.8.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.5 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect | ||
github.com/leodido/go-urn v1.2.4 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.11 // indirect | ||
golang.org/x/arch v0.5.0 // indirect | ||
golang.org/x/crypto v0.14.0 // indirect | ||
golang.org/x/net v0.17.0 // indirect | ||
golang.org/x/sys v0.13.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
golang.org/x/arch v0.3.0 // indirect | ||
golang.org/x/crypto v0.9.0 // indirect | ||
golang.org/x/net v0.10.0 // indirect | ||
golang.org/x/sys v0.8.0 // indirect | ||
golang.org/x/text v0.9.0 // indirect | ||
google.golang.org/protobuf v1.30.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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,24 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gin-gonic/gin" | ||
"post-go/controllers" | ||
) | ||
|
||
func router(r *gin.Engine) { | ||
r.GET("/", controllers.HelloWorld) | ||
} | ||
import "github.com/gin-gonic/gin" | ||
|
||
func main() { | ||
r := gin.Default() | ||
r := gin.Default() | ||
router(r) | ||
err := r.Run() | ||
|
||
router(r) | ||
err := r.Run() | ||
|
||
if err != nil { | ||
fmt.Println("Couldn't Run the app!, try again or verify your connection") | ||
return | ||
} | ||
if err != nil { | ||
return | ||
} | ||
} | ||
|
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,24 @@ | ||
package main | ||
|
||
import ( | ||
"bective/types" | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
func RouteNotFound(c *gin.Context) { | ||
c.JSON(http.StatusNotFound, gin.H{"message": "Page not found"}) | ||
} | ||
|
||
func todosHandler(r *gin.Engine) { | ||
todo := new(types.Todo) | ||
r.GET("/todos", todo.GetTodos) | ||
r.POST("/todo", todo.GetTodos) | ||
} | ||
|
||
func router(r *gin.Engine) { | ||
|
||
r.POST("/auth", AuthController) | ||
todosHandler(r) | ||
r.NoRoute(RouteNotFound) | ||
} |
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,42 @@ | ||
package types | ||
|
||
import ( | ||
"bective/utils" | ||
"encoding/json" | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
type Todo struct { | ||
Id int `json:"id"` | ||
Title string `json:"title"` | ||
Description string `json:"description"` | ||
} | ||
|
||
type Todos struct { | ||
Todos []Todo `json:"todos"` | ||
} | ||
|
||
func (t *Todo) GetTodos(c *gin.Context) { | ||
var todos Todos | ||
|
||
fileBytes := utils.JsonToBytes("data/data.json") | ||
c.JSON(http.StatusOK, todos.FileToTodos(fileBytes)) | ||
} | ||
|
||
func (t *Todo) CreateTodo(c *gin.Context) { | ||
c.JSON(http.StatusOK, gin.H{ | ||
"todos": "You just created a todo", | ||
}) | ||
} | ||
|
||
func (t *Todos) FileToTodos(fileByteValue []byte) Todos { | ||
var todos Todos | ||
utils.CheckError(json.Unmarshal(fileByteValue, &todos)) | ||
return todos | ||
} | ||
|
||
func (t *Todos) TodosToFile() Todos { | ||
var todos Todos | ||
return todos | ||
} |
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,7 @@ | ||
package utils | ||
|
||
func CheckError(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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,22 @@ | ||
package utils | ||
|
||
import ( | ||
"io" | ||
"os" | ||
) | ||
|
||
func JsonToBytes(filepath string) []byte { | ||
file, err := os.Open(filepath) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
fileByteValue, err := io.ReadAll(file) | ||
|
||
if err != nil { | ||
CheckError(file.Close()) | ||
panic(err) | ||
} | ||
CheckError(file.Close()) | ||
return fileByteValue | ||
} |