Deprecated messages, linting, nosec, typo's

pull/6/head
Fenny 2020-02-03 13:40:50 +01:00
parent 9ddf4625c0
commit f6489b7405
6 changed files with 75 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -9,6 +9,7 @@ package fiber
import ( import (
"encoding/base64" "encoding/base64"
"fmt"
"log" "log"
"mime" "mime"
"mime/multipart" "mime/multipart"
@ -239,13 +240,25 @@ func (ctx *Ctx) Hostname() string {
return getString(ctx.Fasthttp.URI().Host()) 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 // IP : https://gofiber.github.io/fiber/#/context?id=Ip
func (ctx *Ctx) IP() string { func (ctx *Ctx) IP() string {
return ctx.Fasthttp.RemoteIP().String() return ctx.Fasthttp.RemoteIP().String()
} }
// Ips : https://gofiber.github.io/fiber/#/context?id=ips // Ips : DEPRECATED
func (ctx *Ctx) Ips() []string { 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), ",") ips := strings.Split(ctx.Get(fasthttp.HeaderXForwardedFor), ",")
for i := range ips { for i := range ips {
ips[i] = strings.TrimSpace(ips[i]) ips[i] = strings.TrimSpace(ips[i])
@ -290,6 +303,12 @@ func (ctx *Ctx) MultipartForm() (*multipart.Form, error) {
return ctx.Fasthttp.MultipartForm() 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 // OriginalURL : https://gofiber.github.io/fiber/#/context?id=originalurl
func (ctx *Ctx) OriginalURL() string { func (ctx *Ctx) OriginalURL() string {
return getString(ctx.Fasthttp.Request.Header.RequestURI()) return getString(ctx.Fasthttp.Request.Header.RequestURI())
@ -366,6 +385,12 @@ func (ctx *Ctx) Subdomains() (subs []string) {
return subs 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 // XHR : https://gofiber.github.io/fiber/#/context?id=xhr
func (ctx *Ctx) XHR() bool { func (ctx *Ctx) XHR() bool {
return ctx.Get("X-Requested-With") == "XMLHttpRequest" 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 // JSON : https://gofiber.github.io/fiber/#/context?id=json
func (ctx *Ctx) JSON(v interface{}) error { func (ctx *Ctx) JSON(v interface{}) error {
raw, err := jsoniter.Marshal(&v) raw, err := jsoniter.Marshal(&v)
@ -169,12 +175,24 @@ func (ctx *Ctx) JSON(v interface{}) error {
return nil 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 // JSONBytes : https://gofiber.github.io/fiber/#/context?id=jsonbytes
func (ctx *Ctx) JSONBytes(raw []byte) { func (ctx *Ctx) JSONBytes(raw []byte) {
ctx.Fasthttp.Response.Header.SetContentType(contentTypeJSON) ctx.Fasthttp.Response.Header.SetContentType(contentTypeJSON)
ctx.Fasthttp.Response.SetBodyString(getString(raw)) 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 // JSONP : https://gofiber.github.io/fiber/#/context?id=jsonp
func (ctx *Ctx) JSONP(v interface{}, cb ...string) error { func (ctx *Ctx) JSONP(v interface{}, cb ...string) error {
raw, err := jsoniter.Marshal(&v) raw, err := jsoniter.Marshal(&v)
@ -195,6 +213,12 @@ func (ctx *Ctx) JSONP(v interface{}, cb ...string) error {
return nil 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 // JSONString : https://gofiber.github.io/fiber/#/context?id=jsonstring
func (ctx *Ctx) JSONString(raw string) { func (ctx *Ctx) JSONString(raw string) {
ctx.Fasthttp.Response.Header.SetContentType(contentTypeJSON) 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 // XML : https://gofiber.github.io/fiber/#/context?id=xml
func (ctx *Ctx) XML(v interface{}) error { func (ctx *Ctx) XML(v interface{}) error {
raw, err := xml.Marshal(v) raw, err := xml.Marshal(v)

View File

@ -10,6 +10,7 @@ package fiber
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"regexp" "regexp"
"strings" "strings"
"unsafe" "unsafe"
@ -78,10 +79,22 @@ func getStatus(status int) (msg string) {
return statusMessages[status] 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 { func getString(b []byte) string {
return *(*string)(unsafe.Pointer(&b)) return *(*string)(unsafe.Pointer(&b))
} }
func getBytes(s string) []byte { // #nosec G103
return *(*[]byte)(unsafe.Pointer(&s)) // 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
} }