Skip to content

Commit

Permalink
feat: done
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvcodes committed Jun 19, 2024
1 parent 07d0050 commit c35da48
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 199 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 gominima
Copyright (c) 2024 gominima

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ package main
import "github.com/gominima/minima"

func main() {
app := minima.New()
app := minima.Engine()

app.Get("/", func(res *minima.Response, req *minima.Request) {
res.OK().Send("Hello World")
Expand Down
10 changes: 7 additions & 3 deletions _examples/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
/**
* Minima is a free and open source software under Mit license
Copyright (c) 2021 gominima
Copyright (c) 2024 gominima
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -37,17 +37,21 @@ import (
)

func main() {
app := minima.New()
app := minima.Engine()
app.UseRaw(SimpleTest())
app.UseRouter(rtr.Router())
app.UseGroup(group.RouteGroup())
app.File("/main.html", "./static/main.html")
app.Static("/static", "./static")
app.Post("/post", func(res *minima.Response, req *minima.Request) {
fmt.Println(req.GetBodyValue("main"))
res.Send("Hello")
})
app.Get("/", func(res *minima.Response, req *minima.Request) {
res.Send("Hello")
res.Send(req.Query("name"))
})

app.Listen(":3000")
}

Expand Down
5 changes: 3 additions & 2 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package minima
/**
* Minima is a free and open source software under Mit license
Copyright (c) 2021 gominima
Copyright (c) 2024 gominima
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -33,7 +33,8 @@ import "net/http"

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

/**
/*
*
n* @info Create a middleware chain
*/
func Chain(middlewares ...func(http.Handler) http.Handler) Middlewares {
Expand Down
37 changes: 1 addition & 36 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
module github.com/gominima/minima

go 1.17

require github.com/stretchr/testify v1.7.0

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
)

//
// Minima is a free and open source software under Mit license

//Copyright (c) 2021 gominima

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to= deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// Authors @apoorvcodes @megatank58
// Maintainers @Panquesito7 @savioxavier @Shubhaankar-Sharma @apoorvcodes @megatank58
// Thank you for showing interest in minima and for this beautiful community
go 1.22.3
12 changes: 0 additions & 12 deletions go.sum

This file was deleted.

53 changes: 19 additions & 34 deletions minima.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package minima
/**
* Minima is a free and open source software under Mit license
Copyright (c) 2021 gominima
Copyright (c) 2024 gominima
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -57,32 +57,29 @@ type Minima struct {
drain time.Duration
}

var (
red = "\u001b[31m"
green = "\u001b[32m"
yellow = "\u001b[33m"
blue = "\u001B[36m"
reset = "\u001b[0m"
version = "1.1.5"
)


/**
* @info Make a new default minima instance
* @example `
func main() {
app := minima.New()
/*
*
app.Get("/", func(res *minima.Response, req *minima.Request) {
res.Status(200).Send("Hello World")
})
- @info Make a new default minima instance
- @example `
func main() {
app := minima.New()
app.Get("/", func(res *minima.Response, req *minima.Request) {
res.Status(200).Send("Hello World")
})
app.Listen(":3000")
}
app.Listen(":3000")
}
`
* @returns {minima}
- @returns {minima}
*/
func New() *Minima {
func Engine() *Minima {
m := &Minima{
drain: 0,
router: NewRouter(),
Expand All @@ -102,19 +99,6 @@ func (m *Minima) Listen(addr string) error {
}
m.server = &http.Server{Addr: addr, Handler: m}
m.started = true

banner := fmt.Sprintf(`
%s __ __ _ __ _ _ __ __ ____
%s | \/ || || \| || || \/ | / () \
%s |_|\/|_||_||_|\__||_||_|\/|_|/__/\__\ %s
%s The Go framework to scale
%s___________________________________________
%s Server started at port %s %v
%s
`, green, green, green, version, blue, red, blue, yellow, addr, reset)

fmt.Println(banner)

return m.server.ListenAndServe()
}

Expand All @@ -133,6 +117,7 @@ func (m *Minima) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Printf("Error parsing form: %s", err)
return
}

if m.router.handler != nil {
m.router.handler.ServeHTTP(w, r)
}
Expand Down
74 changes: 0 additions & 74 deletions minima_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package minima
/**
* Minima is a free and open source software under Mit license
Copyright (c) 2021 gominima
Copyright (c) 2024 gominima
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
45 changes: 45 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// ParseRequestBody parses the request body based on the Content-Type header.
package minima

import (
"encoding/json"
"net/http"
)

func ParseRequestBody(r *http.Request) (map[string]interface{}, error) {
if r.Body == nil {
return nil, nil
}
defer r.Body.Close()

switch r.Header.Get("Content-Type") {
case "application/x-www-form-urlencoded":
return parseFormData(r)
case "application/json":
return parseJSONData(r)
default:
return nil, nil // Ignore other content types
}
}

func parseFormData(r *http.Request) (map[string]interface{}, error) {
if err := r.ParseForm(); err != nil {
return nil, err
}

data := make(map[string]interface{}, len(r.Form))
for k, v := range r.Form {
data[k] = v
}

return data, nil
}

func parseJSONData(r *http.Request) (map[string]interface{}, error) {
var data map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
return nil, err
}

return data, nil
}
Loading

0 comments on commit c35da48

Please sign in to comment.