1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-22 22:23:42 +00:00

Merge pull request #6 from Fenny/master

Add deprecated alerts, linting, nosec, typo's
This commit is contained in:
Fenny 2020-02-03 07:42:50 -05:00 committed by GitHub
commit 671b244d98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 6 deletions

View File

@ -14,7 +14,7 @@ import (
const (
// Version : Fiber version
Version = "1.2.3"
Version = "1.3.0"
// https://play.golang.org/p/r6GNeV1gbH
banner = "" +
" \x1b[1;32m _____ _ _\n" +

View File

@ -19,7 +19,7 @@
<script>
window.$docsify = {
name: 'Fiber v1.2.3',
name: 'Fiber v1.3.0',
repo: 'gofiber/fiber',
loadSidebar: "sidebar.md",
homepage: 'getting_started.md',

View File

@ -97,6 +97,7 @@ func (r *Fiber) prefork(server *fasthttp.Server, host string, tls ...string) {
// Create babies
childs := make([]*exec.Cmd, runtime.NumCPU())
// #nosec G204
for i := range childs {
childs[i] = exec.Command(os.Args[0], "-prefork", "-child")
childs[i].Stdout = os.Stdout

View File

@ -9,6 +9,7 @@ package fiber
import (
"encoding/base64"
"fmt"
"log"
"mime"
"mime/multipart"
@ -239,13 +240,25 @@ func (ctx *Ctx) Hostname() string {
return getString(ctx.Fasthttp.URI().Host())
}
// Ip : DEPRECATED
func (ctx *Ctx) Ip() string { // NOLINT
fmt.Println("Fiber deprecated c.Ip(): Use c.IP() instead")
return ctx.IP()
}
// IP : https://gofiber.github.io/fiber/#/context?id=Ip
func (ctx *Ctx) IP() string {
return ctx.Fasthttp.RemoteIP().String()
}
// Ips : https://gofiber.github.io/fiber/#/context?id=ips
func (ctx *Ctx) Ips() []string {
// Ips : DEPRECATED
func (ctx *Ctx) Ips() []string { // NOLINT
fmt.Println("Fiber deprecated c.Ips(): Use c.IPs() instead")
return ctx.IPs()
}
// IPs : https://gofiber.github.io/fiber/#/context?id=ips
func (ctx *Ctx) IPs() []string {
ips := strings.Split(ctx.Get(fasthttp.HeaderXForwardedFor), ",")
for i := range ips {
ips[i] = strings.TrimSpace(ips[i])
@ -290,6 +303,12 @@ func (ctx *Ctx) MultipartForm() (*multipart.Form, error) {
return ctx.Fasthttp.MultipartForm()
}
// OriginalUrl : DEPRECATED
func (ctx *Ctx) OriginalUrl() string {
fmt.Println("Fiber deprecated c.OriginalUrl(): Use c.OriginalURL() instead")
return ctx.OriginalURL()
}
// OriginalURL : https://gofiber.github.io/fiber/#/context?id=originalurl
func (ctx *Ctx) OriginalURL() string {
return getString(ctx.Fasthttp.Request.Header.RequestURI())
@ -366,6 +385,12 @@ func (ctx *Ctx) Subdomains() (subs []string) {
return subs
}
// Xhr : DEPRECATED
func (ctx *Ctx) Xhr() bool {
fmt.Println("Fiber deprecated c.Xhr(): Use c.XHR() instead")
return ctx.XHR()
}
// XHR : https://gofiber.github.io/fiber/#/context?id=xhr
func (ctx *Ctx) XHR() bool {
return ctx.Get("X-Requested-With") == "XMLHttpRequest"

View File

@ -156,6 +156,12 @@ func (ctx *Ctx) HeadersSent() {
}
// Json : DEPRECATED
func (ctx *Ctx) Json(v interface{}) error {
fmt.Println("Fiber deprecated c.Json(): Use c.JSON() instead")
return ctx.JSON(v)
}
// JSON : https://gofiber.github.io/fiber/#/context?id=json
func (ctx *Ctx) JSON(v interface{}) error {
raw, err := jsoniter.Marshal(&v)
@ -169,12 +175,24 @@ func (ctx *Ctx) JSON(v interface{}) error {
return nil
}
// JsonBytes : DEPRECATED
func (ctx *Ctx) JsonBytes(raw []byte) {
fmt.Println("Fiber deprecated c.JsonBytes(): Use c.JSONBytes() instead")
ctx.JSONBytes(raw)
}
// JSONBytes : https://gofiber.github.io/fiber/#/context?id=jsonbytes
func (ctx *Ctx) JSONBytes(raw []byte) {
ctx.Fasthttp.Response.Header.SetContentType(contentTypeJSON)
ctx.Fasthttp.Response.SetBodyString(getString(raw))
}
// Jsonp : DEPRECATED
func (ctx *Ctx) Jsonp(v interface{}, cb ...string) error {
fmt.Println("Fiber deprecated c.Jsonp(): Use c.JSONP() instead")
return ctx.JSONP(v, cb...)
}
// JSONP : https://gofiber.github.io/fiber/#/context?id=jsonp
func (ctx *Ctx) JSONP(v interface{}, cb ...string) error {
raw, err := jsoniter.Marshal(&v)
@ -195,6 +213,12 @@ func (ctx *Ctx) JSONP(v interface{}, cb ...string) error {
return nil
}
// JsonString : DEPRECATED
func (ctx *Ctx) JsonString(raw string) {
fmt.Println("Fiber deprecated c.JsonString(): Use c.JSONString() instead")
ctx.JSONString(raw)
}
// JSONString : https://gofiber.github.io/fiber/#/context?id=jsonstring
func (ctx *Ctx) JSONString(raw string) {
ctx.Fasthttp.Response.Header.SetContentType(contentTypeJSON)
@ -347,6 +371,12 @@ func (ctx *Ctx) Write(args ...interface{}) {
}
}
// Xml : DEPRECATED
func (ctx *Ctx) Xml(v interface{}) error {
fmt.Println("Fiber deprecated c.Xml(): Use c.XML() instead")
return ctx.XML(v)
}
// XML : https://gofiber.github.io/fiber/#/context?id=xml
func (ctx *Ctx) XML(v interface{}) error {
raw, err := xml.Marshal(v)

View File

@ -10,6 +10,7 @@ package fiber
import (
"os"
"path/filepath"
"reflect"
"regexp"
"strings"
"unsafe"
@ -78,10 +79,22 @@ func getStatus(status int) (msg string) {
return statusMessages[status]
}
// #nosec G103
// getString converts byte slice to a string without memory allocation.
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
func getString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
func getBytes(s string) []byte {
return *(*[]byte)(unsafe.Pointer(&s))
// #nosec G103
// getBytes converts string to a byte slice without memory allocation.
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
func getBytes(s string) (b []byte) {
// return *(*[]byte)(unsafe.Pointer(&s))
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := *(*reflect.StringHeader)(unsafe.Pointer(&s))
bh.Data = sh.Data
bh.Len = sh.Len
bh.Cap = sh.Len
return b
}