Skip to content

Commit c35da48

Browse files
committed
feat: done
1 parent 07d0050 commit c35da48

15 files changed

+117
-199
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 gominima
3+
Copyright (c) 2024 gominima
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ package main
4848
import "github.com/gominima/minima"
4949

5050
func main() {
51-
app := minima.New()
51+
app := minima.Engine()
5252

5353
app.Get("/", func(res *minima.Response, req *minima.Request) {
5454
res.OK().Send("Hello World")

_examples/start.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
/**
44
* Minima is a free and open source software under Mit license
55
6-
Copyright (c) 2021 gominima
6+
Copyright (c) 2024 gominima
77
88
Permission is hereby granted, free of charge, to any person obtaining a copy
99
of this software and associated documentation files (the "Software"), to deal
@@ -37,17 +37,21 @@ import (
3737
)
3838

3939
func main() {
40-
app := minima.New()
40+
app := minima.Engine()
4141
app.UseRaw(SimpleTest())
4242
app.UseRouter(rtr.Router())
4343
app.UseGroup(group.RouteGroup())
4444
app.File("/main.html", "./static/main.html")
4545
app.Static("/static", "./static")
46+
app.Post("/post", func(res *minima.Response, req *minima.Request) {
47+
fmt.Println(req.GetBodyValue("main"))
48+
res.Send("Hello")
49+
})
4650
app.Get("/", func(res *minima.Response, req *minima.Request) {
4751
res.Send("Hello")
4852
res.Send(req.Query("name"))
4953
})
50-
54+
5155
app.Listen(":3000")
5256
}
5357

chain.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package minima
33
/**
44
* Minima is a free and open source software under Mit license
55
6-
Copyright (c) 2021 gominima
6+
Copyright (c) 2024 gominima
77
88
Permission is hereby granted, free of charge, to any person obtaining a copy
99
of this software and associated documentation files (the "Software"), to deal
@@ -33,7 +33,8 @@ import "net/http"
3333

3434
type Middlewares []func(http.Handler) http.Handler
3535

36-
/**
36+
/*
37+
*
3738
n* @info Create a middleware chain
3839
*/
3940
func Chain(middlewares ...func(http.Handler) http.Handler) Middlewares {

go.mod

+1-36
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,3 @@
11
module github.com/gominima/minima
22

3-
go 1.17
4-
5-
require github.com/stretchr/testify v1.7.0
6-
7-
require (
8-
github.com/davecgh/go-spew v1.1.0 // indirect
9-
github.com/pmezard/go-difflib v1.0.0 // indirect
10-
gopkg.in/yaml.v3 v3.0.0 // indirect
11-
)
12-
13-
//
14-
// Minima is a free and open source software under Mit license
15-
16-
//Copyright (c) 2021 gominima
17-
18-
// Permission is hereby granted, free of charge, to any person obtaining a copy
19-
// of this software and associated documentation files (the "Software"), to= deal
20-
// in the Software without restriction, including without limitation the rights
21-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22-
// copies of the Software, and to permit persons to whom the Software is
23-
// furnished to do so, subject to the following conditions:
24-
25-
// The above copyright notice and this permission notice shall be included in all
26-
// copies or substantial portions of the Software.
27-
28-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34-
// SOFTWARE.
35-
36-
// Authors @apoorvcodes @megatank58
37-
// Maintainers @Panquesito7 @savioxavier @Shubhaankar-Sharma @apoorvcodes @megatank58
38-
// Thank you for showing interest in minima and for this beautiful community
3+
go 1.22.3

go.sum

-12
This file was deleted.

minima.go

+19-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package minima
33
/**
44
* Minima is a free and open source software under Mit license
55
6-
Copyright (c) 2021 gominima
6+
Copyright (c) 2024 gominima
77
88
Permission is hereby granted, free of charge, to any person obtaining a copy
99
of this software and associated documentation files (the "Software"), to deal
@@ -57,32 +57,29 @@ type Minima struct {
5757
drain time.Duration
5858
}
5959

60-
var (
61-
red = "\u001b[31m"
62-
green = "\u001b[32m"
63-
yellow = "\u001b[33m"
64-
blue = "\u001B[36m"
65-
reset = "\u001b[0m"
66-
version = "1.1.5"
67-
)
6860

6961

70-
/**
71-
* @info Make a new default minima instance
72-
* @example `
73-
func main() {
74-
app := minima.New()
62+
/*
63+
*
7564
76-
app.Get("/", func(res *minima.Response, req *minima.Request) {
77-
res.Status(200).Send("Hello World")
78-
})
65+
- @info Make a new default minima instance
66+
67+
- @example `
68+
69+
func main() {
70+
app := minima.New()
71+
72+
app.Get("/", func(res *minima.Response, req *minima.Request) {
73+
res.Status(200).Send("Hello World")
74+
})
75+
76+
app.Listen(":3000")
77+
}
7978
80-
app.Listen(":3000")
81-
}
8279
`
83-
* @returns {minima}
80+
- @returns {minima}
8481
*/
85-
func New() *Minima {
82+
func Engine() *Minima {
8683
m := &Minima{
8784
drain: 0,
8885
router: NewRouter(),
@@ -102,19 +99,6 @@ func (m *Minima) Listen(addr string) error {
10299
}
103100
m.server = &http.Server{Addr: addr, Handler: m}
104101
m.started = true
105-
106-
banner := fmt.Sprintf(`
107-
%s __ __ _ __ _ _ __ __ ____
108-
%s | \/ || || \| || || \/ | / () \
109-
%s |_|\/|_||_||_|\__||_||_|\/|_|/__/\__\ %s
110-
%s The Go framework to scale
111-
%s___________________________________________
112-
%s Server started at port %s %v
113-
%s
114-
`, green, green, green, version, blue, red, blue, yellow, addr, reset)
115-
116-
fmt.Println(banner)
117-
118102
return m.server.ListenAndServe()
119103
}
120104

@@ -133,6 +117,7 @@ func (m *Minima) ServeHTTP(w http.ResponseWriter, r *http.Request) {
133117
log.Printf("Error parsing form: %s", err)
134118
return
135119
}
120+
136121
if m.router.handler != nil {
137122
m.router.handler.ServeHTTP(w, r)
138123
}

minima_test.go

-74
This file was deleted.

node.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package minima
33
/**
44
* Minima is a free and open source software under Mit license
55
6-
Copyright (c) 2021 gominima
6+
Copyright (c) 2024 gominima
77
88
Permission is hereby granted, free of charge, to any person obtaining a copy
99
of this software and associated documentation files (the "Software"), to deal

parser.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// ParseRequestBody parses the request body based on the Content-Type header.
2+
package minima
3+
4+
import (
5+
"encoding/json"
6+
"net/http"
7+
)
8+
9+
func ParseRequestBody(r *http.Request) (map[string]interface{}, error) {
10+
if r.Body == nil {
11+
return nil, nil
12+
}
13+
defer r.Body.Close()
14+
15+
switch r.Header.Get("Content-Type") {
16+
case "application/x-www-form-urlencoded":
17+
return parseFormData(r)
18+
case "application/json":
19+
return parseJSONData(r)
20+
default:
21+
return nil, nil // Ignore other content types
22+
}
23+
}
24+
25+
func parseFormData(r *http.Request) (map[string]interface{}, error) {
26+
if err := r.ParseForm(); err != nil {
27+
return nil, err
28+
}
29+
30+
data := make(map[string]interface{}, len(r.Form))
31+
for k, v := range r.Form {
32+
data[k] = v
33+
}
34+
35+
return data, nil
36+
}
37+
38+
func parseJSONData(r *http.Request) (map[string]interface{}, error) {
39+
var data map[string]interface{}
40+
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
41+
return nil, err
42+
}
43+
44+
return data, nil
45+
}

0 commit comments

Comments
 (0)