Browse Source

formatting

Former-commit-id: 037081db5d6d4434e873ca8b75334ee43e046b6a
pull/1789/head
Gerasimos (Makis) Maropoulos 2 years ago
parent
commit
07046ab978
  1. 6
      _benchmarks/iris-mvc-templates/controllers/home_controller.go
  2. 11
      _examples/authentication/oauth2/main.go
  3. 1
      _examples/experimental-handlers/casbin/wrapper/main_test.go
  4. 2
      _examples/file-server/basic/main_test.go
  5. 1
      _examples/hero/basic/main.go
  6. 1
      _examples/http-listening/listen-addr/omit-server-errors/main_test.go
  7. 1
      _examples/http_request/read-json-struct-validation/main.go
  8. 1
      _examples/http_request/read-json/main.go
  9. 1
      _examples/http_request/read-many/main.go
  10. 3
      _examples/http_request/request-logger/main.go
  11. 1
      _examples/http_request/upload-file/main.go
  12. 1
      _examples/http_request/upload-files/main.go
  13. 1
      _examples/http_responsewriter/content-negotiation/main_test.go
  14. 3
      _examples/http_responsewriter/herotemplate/app.go
  15. 1
      _examples/http_responsewriter/herotemplate/template/userlist.html.go
  16. 1
      _examples/http_responsewriter/herotemplate/template/userlistwriter.html.go
  17. 1
      _examples/http_responsewriter/sse-third-party/main.go
  18. 9
      _examples/miscellaneous/i18n/main.go
  19. 1
      _examples/miscellaneous/i18n/main_test.go
  20. 1
      _examples/mvc/login/web/controllers/user_controller.go
  21. 1
      _examples/routing/basic/main.go
  22. 1
      _examples/routing/basic/main_test.go
  23. 1
      _examples/routing/custom-wrapper/main.go
  24. 2
      _examples/routing/main_test.go
  25. 1
      _examples/routing/reverse/main.go
  26. 1
      _examples/routing/route-state/main.go
  27. 6
      _examples/sessions/database/badger/main.go
  28. 6
      _examples/sessions/database/boltdb/main.go
  29. 6
      _examples/sessions/database/redis/main.go
  30. 7
      _examples/sessions/middleware/main.go
  31. 1
      _examples/sessions/overview/main.go
  32. 7
      _examples/sessions/securecookie/main.go
  33. 1
      _examples/subdomains/redirect/main_test.go
  34. 1
      _examples/subdomains/www/main_test.go
  35. 1
      _examples/testing/httptest/main_test.go
  36. 1
      _examples/tutorial/api-for-apache-kafka/src/main.go
  37. 4
      _examples/tutorial/dropzonejs/src/main.go
  38. 2
      _examples/tutorial/mongodb/main.go
  39. 1
      _examples/tutorial/url-shortener/main.go
  40. 1
      _examples/tutorial/url-shortener/main_test.go
  41. 7
      _examples/tutorial/url-shortener/store.go
  42. 2
      _examples/view/overview/main.go
  43. 1
      _examples/view/template_html_3/main.go
  44. 2
      _examples/view/template_jet_0/main.go
  45. 1
      _examples/view/template_pug_0/main.go
  46. 1
      _examples/view/write-to/main.go
  47. 1
      cache/browser_test.go
  48. 3
      cache/cache_test.go
  49. 1
      cache/client/handler.go
  50. 1
      cache/client/rule/chained.go
  51. 1
      cache/entry/entry.go
  52. 1
      cache/uri/uribuilder.go
  53. 1
      configuration_test.go
  54. 24
      context/context.go
  55. 1
      context/gzip_response_writer.go
  56. 210
      context/request_params.go
  57. 1
      context/response_recorder.go
  58. 1
      context/response_writer.go
  59. 6
      core/errors/errors.go
  60. 2
      core/errors/errors_test.go
  61. 1
      core/errors/reporter.go
  62. 3
      core/handlerconv/from_std.go
  63. 1
      core/handlerconv/from_std_test.go
  64. 1
      core/host/supervisor_task_example_test.go
  65. 7
      core/host/supervisor_test.go
  66. 7
      core/netutil/addr.go
  67. 1
      core/netutil/tcp.go
  68. 32
      core/router/api_builder.go
  69. 1
      core/router/handler.go
  70. 1
      core/router/mime.go
  71. 91
      core/router/path_test.go
  72. 1
      core/router/route.go
  73. 6
      core/router/route_test.go
  74. 1
      core/router/router.go
  75. 1
      core/router/router_handlers_order_test.go
  76. 8
      core/router/router_wildcard_root_test.go
  77. 3
      core/router/status.go
  78. 1
      core/router/status_test.go
  79. 4
      hero/di/func.go
  80. 5
      hero/di/values.go
  81. 1
      hero/func_result.go
  82. 5
      hero/handler.go
  83. 1
      hero/param_test.go
  84. 6
      iris.go
  85. 1
      macro/interpreter/lexer/lexer.go
  86. 263
      macro/interpreter/parser/parser_test.go
  87. 1
      middleware/basicauth/basicauth.go
  88. 2
      middleware/i18n/i18n.go
  89. 5
      middleware/logger/logger.go
  90. 1
      middleware/recaptcha/recaptcha.go
  91. 1
      middleware/recover/recover.go
  92. 1
      mvc/controller.go
  93. 11
      mvc/controller_test.go
  94. 8
      mvc/go19.go
  95. 28
      mvc/mvc.go
  96. 1
      sessions/config.go
  97. 3
      sessions/sessiondb/badger/database.go
  98. 3
      sessions/sessiondb/boltdb/database.go
  99. 1
      sessions/sessiondb/redis/database.go
  100. 4
      sessions/sessiondb/redis/driver_radix.go

6
_benchmarks/iris-mvc-templates/controllers/home_controller.go

@ -13,7 +13,8 @@ func (c *HomeController) GetAbout() mvc.Result {
Name: "about.html",
Data: map[string]interface{}{
"Title": "About Page",
"Message": "Your application description page."},
"Message": "Your application description page.",
},
}
}
@ -22,6 +23,7 @@ func (c *HomeController) GetContact() mvc.Result {
Name: "contact.html",
Data: map[string]interface{}{
"Title": "Contact Page",
"Message": "Your application description page."},
"Message": "Your application description page.",
},
}
}

11
_examples/authentication/oauth2/main.go

@ -179,7 +179,6 @@ var SetState = func(ctx iris.Context) string {
}
return "state"
}
// GetState gets the state returned by the provider during the callback.
@ -273,14 +272,14 @@ func main() {
yammer.New(os.Getenv("YAMMER_KEY"), os.Getenv("YAMMER_SECRET"), "http://localhost:3000/auth/yammer/callback"),
onedrive.New(os.Getenv("ONEDRIVE_KEY"), os.Getenv("ONEDRIVE_SECRET"), "http://localhost:3000/auth/onedrive/callback"),
//Pointed localhost.com to http://localhost:3000/auth/yahoo/callback through proxy as yahoo
// Pointed localhost.com to http://localhost:3000/auth/yahoo/callback through proxy as yahoo
// does not allow to put custom ports in redirection uri
yahoo.New(os.Getenv("YAHOO_KEY"), os.Getenv("YAHOO_SECRET"), "http://localhost.com"),
slack.New(os.Getenv("SLACK_KEY"), os.Getenv("SLACK_SECRET"), "http://localhost:3000/auth/slack/callback"),
stripe.New(os.Getenv("STRIPE_KEY"), os.Getenv("STRIPE_SECRET"), "http://localhost:3000/auth/stripe/callback"),
wepay.New(os.Getenv("WEPAY_KEY"), os.Getenv("WEPAY_SECRET"), "http://localhost:3000/auth/wepay/callback", "view_user"),
//By default paypal production auth urls will be used, please set PAYPAL_ENV=sandbox as environment variable for testing
//in sandbox environment
// By default paypal production auth urls will be used, please set PAYPAL_ENV=sandbox as environment variable for testing
// in sandbox environment
paypal.New(os.Getenv("PAYPAL_KEY"), os.Getenv("PAYPAL_SECRET"), "http://localhost:3000/auth/paypal/callback"),
steam.New(os.Getenv("STEAM_KEY"), "http://localhost:3000/auth/steam/callback"),
heroku.New(os.Getenv("HEROKU_KEY"), os.Getenv("HEROKU_SECRET"), "http://localhost:3000/auth/heroku/callback"),
@ -292,7 +291,7 @@ func main() {
discord.New(os.Getenv("DISCORD_KEY"), os.Getenv("DISCORD_SECRET"), "http://localhost:3000/auth/discord/callback", discord.ScopeIdentify, discord.ScopeEmail),
meetup.New(os.Getenv("MEETUP_KEY"), os.Getenv("MEETUP_SECRET"), "http://localhost:3000/auth/meetup/callback"),
//Auth0 allocates domain per customer, a domain must be provided for auth0 to work
// Auth0 allocates domain per customer, a domain must be provided for auth0 to work
auth0.New(os.Getenv("AUTH0_KEY"), os.Getenv("AUTH0_SECRET"), "http://localhost:3000/auth/auth0/callback", os.Getenv("AUTH0_DOMAIN")),
xero.New(os.Getenv("XERO_KEY"), os.Getenv("XERO_SECRET"), "http://localhost:3000/auth/xero/callback"),
)
@ -363,7 +362,6 @@ func main() {
// start of the router
app.Get("/auth/{provider}/callback", func(ctx iris.Context) {
user, err := CompleteUserAuth(ctx)
if err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
@ -394,7 +392,6 @@ func main() {
})
app.Get("/", func(ctx iris.Context) {
ctx.ViewData("", providerIndex)
if err := ctx.View("index.html"); err != nil {

1
_examples/experimental-handlers/casbin/wrapper/main_test.go

@ -71,7 +71,6 @@ func TestCasbinWrapper(t *testing.T) {
for _, tt := range ttAdminDeleted {
check(e, tt.method, tt.path, tt.username, tt.status)
}
}
func check(e *httptest.Expect, method, path, username string, status int) {

2
_examples/file-server/basic/main_test.go

@ -57,7 +57,7 @@ func (r resource) loadFromBase(dir string) string {
}
func TestFileServerBasic(t *testing.T) {
var urls = []resource{
urls := []resource{
"/static/css/main.css",
"/static/js/jquery-2.1.1.js",
"/static/favicon.ico",

1
_examples/hero/basic/main.go

@ -6,7 +6,6 @@ import (
)
func main() {
app := iris.New()
// 1

1
_examples/http-listening/listen-addr/omit-server-errors/main_test.go

@ -45,7 +45,6 @@ func TestListenAddr(t *testing.T) {
if got := log.String(); !strings.Contains(got, expectedMessage) {
t.Fatalf("expecting to log to contains the:\n'%s'\ninstead of:\n'%s'", expectedMessage, got)
}
}
func TestListenAddrWithoutServerErr(t *testing.T) {

1
_examples/http_request/read-json-struct-validation/main.go

@ -131,7 +131,6 @@ func main() {
// hooks right into validator and you can combine with validation tags and still have a
// common error output format.
func UserStructLevelValidation(sl validator.StructLevel) {
user := sl.Current().Interface().(User)
if len(user.FirstName) == 0 && len(user.LastName) == 0 {

1
_examples/http_request/read-json/main.go

@ -32,7 +32,6 @@ type Person struct {
func MyHandler2(ctx iris.Context) {
var persons []Person
err := ctx.ReadJSON(&persons)
if err != nil {
ctx.StatusCode(iris.StatusBadRequest)
ctx.WriteString(err.Error())

1
_examples/http_request/read-many/main.go

@ -20,7 +20,6 @@ func main() {
ctx.WriteString(`The body was empty
or iris.WithoutBodyConsumptionOnUnmarshal option is missing from app.Run.
Check the terminal window for any queries logs.`)
} else {
ctx.WriteString("OK body is still:\n")
ctx.Write(body)

3
_examples/http_request/request-logger/main.go

@ -20,7 +20,7 @@ func main() {
// Query appends the url query to the Path.
Query: true,
//Columns: true,
// Columns: true,
// if !empty then its contents derives from `ctx.Values().Get("logger_message")
// will be added to the logs.
@ -62,5 +62,4 @@ func main() {
// http://lcoalhost:8080/notfoundhere
// see the output on the console.
app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))
}

1
_examples/http_request/upload-file/main.go

@ -113,7 +113,6 @@ func main() {
// assuming that you have a folder named 'uploads'
out, err := os.OpenFile("./uploads/"+fname,
os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.HTML("Error while uploading: <b>" + err.Error() + "</b>")

1
_examples/http_request/upload-files/main.go

@ -84,7 +84,6 @@ func saveUploadedFile(fh *multipart.FileHeader, destDirectory string) (int64, er
out, err := os.OpenFile(filepath.Join(destDirectory, fh.Filename),
os.O_WRONLY|os.O_CREATE, os.FileMode(0666))
if err != nil {
return 0, err
}

1
_examples/http_responsewriter/content-negotiation/main_test.go

@ -74,5 +74,4 @@ func TestContentNegotiation(t *testing.T) {
if expected, got := expectedHTMLResponse, string(rawResponse); expected != got {
t.Fatalf("expected response to be:\n%s but got:\n%s", expected, got)
}
}

3
_examples/http_responsewriter/herotemplate/app.go

@ -14,14 +14,13 @@ import (
// Read more at https://github.com/shiyanhui/hero/hero
func main() {
app := iris.New()
app.Get("/users", func(ctx iris.Context) {
ctx.Gzip(true)
ctx.ContentType("text/html")
var userList = []string{
userList := []string{
"Alice",
"Bob",
"Tom",

1
_examples/http_responsewriter/herotemplate/template/userlist.html.go

@ -37,5 +37,4 @@ func UserList(userList []string, buffer *bytes.Buffer) {
</body>
</html>
`)
}

1
_examples/http_responsewriter/herotemplate/template/userlistwriter.html.go

@ -40,5 +40,4 @@ func UserListToWriter(userList []string, w io.Writer) (int, error) {
</html>
`)
return w.Write(_buffer.Bytes())
}

1
_examples/http_responsewriter/sse-third-party/main.go

@ -42,7 +42,6 @@ func main() {
s.Publish("messages", &sse.Event{
Data: []byte("third message"),
})
}() // ...
app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))

9
_examples/miscellaneous/i18n/main.go

@ -14,11 +14,12 @@ func newApp() *iris.Application {
Languages: map[string]string{
"en-US": "./locales/locale_en-US.ini",
"el-GR": "./locales/locale_el-GR.ini",
"zh-CN": "./locales/locale_zh-CN.ini"}})
"zh-CN": "./locales/locale_zh-CN.ini",
},
})
app.Use(globalLocale)
app.Get("/", func(ctx iris.Context) {
// it tries to find the language by:
// ctx.Values().GetString("language")
// if that was empty then
@ -47,7 +48,9 @@ func newApp() *iris.Application {
URLParameter: "lang",
Languages: map[string]string{
"en-US": "./locales/locale_multi_first_en-US.ini, ./locales/locale_multi_second_en-US.ini",
"el-GR": "./locales/locale_multi_first_el-GR.ini, ./locales/locale_multi_second_el-GR.ini"}})
"el-GR": "./locales/locale_multi_first_el-GR.ini, ./locales/locale_multi_second_el-GR.ini",
},
})
app.Get("/multi", multiLocale, func(ctx iris.Context) {
language := ctx.Values().GetString(ctx.Application().ConfigurationReadOnly().GetTranslateLanguageContextKey())

1
_examples/miscellaneous/i18n/main_test.go

@ -45,5 +45,4 @@ func TestI18n(t *testing.T) {
Body().Equal(elgrMulti)
e.GET("/multi").WithQueryString("lang=en-US").Expect().Status(httptest.StatusOK).
Body().Equal(enusMulti)
}

1
_examples/mvc/login/web/controllers/user_controller.go

@ -96,7 +96,6 @@ func (c *UserController) PostRegister() mvc.Result {
// but it's good to know you can set a custom code;
// Code: 303,
}
}
var loginStaticView = mvc.View{

1
_examples/routing/basic/main.go

@ -71,7 +71,6 @@ func newApp() *iris.Application {
// Pssst, don't forget dynamic-path example for more "magic"!
app.Get("/api/users/{userid:uint64 min(1)}", func(ctx iris.Context) {
userID, err := ctx.Params().GetUint64("userid")
if err != nil {
ctx.Writef("error while trying to parse userid parameter," +
"this will never happen if :uint64 is being used because if it's not a valid uint64 it will fire Not Found automatically.")

1
_examples/routing/basic/main_test.go

@ -85,5 +85,4 @@ func TestRoutingBasic(t *testing.T) {
e.Request("GET", "/").WithURL("http://any-subdomain-here.example.com").Expect().Status(httptest.StatusOK).
Body().Equal(expectedSubdomainWildcardIndexResponse)
}

1
_examples/routing/custom-wrapper/main.go

@ -11,7 +11,6 @@ import (
// You can use the .WrapRouter to add custom logic when or when not the router should
// be executed in order to execute the registered routes' handlers.
func newApp() *iris.Application {
app := iris.New()
app.OnErrorCode(iris.StatusNotFound, func(ctx iris.Context) {

2
_examples/routing/main_test.go

@ -75,7 +75,7 @@ func TestRouting(t *testing.T) {
app := newApp()
e := httptest.New(t, app)
var tests = []troute{
tests := []troute{
// GET
newTroute("GET", "", "/healthcheck", httptest.StatusOK),
newTroute("GET", "", "/games/{gameID}/clans", httptest.StatusOK, "gameID", "42"),

1
_examples/routing/reverse/main.go

@ -36,5 +36,4 @@ func main() {
// See view/template_html_4 example for more reverse routing examples
// using the reverse router component and the {{url}} and {{urlpath}} template functions.
app.Run(iris.Addr(":8080"))
}

1
_examples/routing/route-state/main.go

@ -16,7 +16,6 @@ func main() {
})
app.Get("/change", func(ctx iris.Context) {
if none.IsOnline() {
none.Method = iris.MethodNone
} else {

6
_examples/sessions/database/badger/main.go

@ -41,10 +41,10 @@ func main() {
})
app.Get("/set", func(ctx iris.Context) {
s := sess.Start(ctx)
//set session values
// set session values
s.Set("name", "iris")
//test if set here
// test if set here
ctx.Writef("All ok session value of the 'name' is: %s", s.GetString("name"))
})
@ -83,7 +83,7 @@ func main() {
})
app.Get("/destroy", func(ctx iris.Context) {
//destroy, removes the entire session data and cookie
// destroy, removes the entire session data and cookie
sess.Destroy(ctx)
})

6
_examples/sessions/database/boltdb/main.go

@ -42,10 +42,10 @@ func main() {
})
app.Get("/set", func(ctx iris.Context) {
s := sess.Start(ctx)
//set session values
// set session values
s.Set("name", "iris")
//test if set here
// test if set here
ctx.Writef("All ok session value of the 'name' is: %s", s.GetString("name"))
})
@ -84,7 +84,7 @@ func main() {
})
app.Get("/destroy", func(ctx iris.Context) {
//destroy, removes the entire session data and cookie
// destroy, removes the entire session data and cookie
sess.Destroy(ctx)
})

6
_examples/sessions/database/redis/main.go

@ -60,10 +60,10 @@ func main() {
})
app.Get("/set", func(ctx iris.Context) {
s := sess.Start(ctx)
//set session values
// set session values
s.Set("name", "iris")
//test if set here
// test if set here
ctx.Writef("All ok session value of the 'name' is: %s", s.GetString("name"))
})
@ -120,7 +120,7 @@ func main() {
})
app.Get("/destroy", func(ctx iris.Context) {
//destroy, removes the entire session data and cookie
// destroy, removes the entire session data and cookie
sess.Destroy(ctx)
})

7
_examples/sessions/middleware/main.go

@ -46,12 +46,12 @@ func main() {
ctx.HTML("</ul>")
})
//set session values.
// set session values.
app.Get("/set", func(ctx iris.Context) {
session := sessions.Get(ctx)
session.Set("name", "iris")
//test if set here.
// test if set here.
ctx.Writef("All ok session set to: %s", session.GetString("name"))
// Set will set the value as-it-is,
@ -97,7 +97,7 @@ func main() {
})
app.Get("/destroy", func(ctx iris.Context) {
//destroy, removes the entire session data and cookie
// destroy, removes the entire session data and cookie
// sess.Destroy(ctx)
// or
sessions.Get(ctx).Destroy()
@ -123,7 +123,6 @@ func main() {
// try to change it, if we used `Set` instead of `SetImmutable` this
// change will affect the underline array of the session's value "businessEdit", but now it will not.
businessGet[0].Name = "Gabriel"
})
app.Get("/get_immutable", func(ctx iris.Context) {

1
_examples/sessions/overview/main.go

@ -12,7 +12,6 @@ var (
)
func secret(ctx iris.Context) {
// Check if user is authenticated
if auth, _ := sess.Start(ctx).GetBoolean("authenticated"); !auth {
ctx.StatusCode(iris.StatusForbidden)

7
_examples/sessions/securecookie/main.go

@ -34,12 +34,11 @@ func newApp() *iris.Application {
ctx.Writef("You should navigate to the /set, /get, /delete, /clear,/destroy instead")
})
app.Get("/set", func(ctx iris.Context) {
//set session values
// set session values
s := mySessions.Start(ctx)
s.Set("name", "iris")
//test if set here
// test if set here
ctx.Writef("All ok session set to: %s", s.GetString("name"))
})
@ -68,7 +67,7 @@ func newApp() *iris.Application {
})
app.Get("/destroy", func(ctx iris.Context) {
//destroy, removes the entire session data and cookie
// destroy, removes the entire session data and cookie
mySessions.Destroy(ctx)
})
// Note about destroy:

1
_examples/subdomains/redirect/main_test.go

@ -26,5 +26,4 @@ func TestSubdomainRedirectWWW(t *testing.T) {
for _, test := range tests {
e.GET(test.path).Expect().Status(httptest.StatusOK).Body().Equal(test.response)
}
}

1
_examples/subdomains/www/main_test.go

@ -54,5 +54,4 @@ func TestSubdomainWWW(t *testing.T) {
Status(httptest.StatusOK).
Body().Equal(test.response())
}
}

1
_examples/testing/httptest/main_test.go

@ -27,5 +27,4 @@ func TestNewApp(t *testing.T) {
// with invalid basic auth
e.GET("/admin/settings").WithBasicAuth("invalidusername", "invalidpassword").
Expect().Status(httptest.StatusUnauthorized)
}

1
_examples/tutorial/api-for-apache-kafka/src/main.go

@ -375,5 +375,4 @@ func getTopicConsumeSSEHandler(ctx iris.Context) {
flusher.Flush()
}
}
}

4
_examples/tutorial/dropzonejs/src/main.go

@ -32,7 +32,6 @@ type uploadedFiles struct {
}
func scanUploads(dir string) *uploadedFiles {
f := new(uploadedFiles)
lindex := dir[len(dir)-1]
@ -54,7 +53,6 @@ func scanUploads(dir string) *uploadedFiles {
func (f *uploadedFiles) scan(dir string) {
f.dir = dir
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
// if it's directory or a thumbnail we saved earlier, skip it.
if info.IsDir() || strings.HasPrefix(info.Name(), "thumbnail_") {
return nil
@ -117,7 +115,6 @@ func (f *uploadedFiles) createThumbnail(uf uploadedFile) {
png.Encode(out, resized)
}
// and so on... you got the point, this code can be simplify, as a practise.
}
func main() {
@ -152,7 +149,6 @@ func main() {
// assuming that you have a folder named 'uploads'
out, err := os.OpenFile(uploadsDir+fname,
os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Application().Logger().Warnf("Error while preparing the new file: %v", err.Error())

2
_examples/tutorial/mongodb/main.go

@ -26,7 +26,7 @@ import (
const version = "0.0.1"
func init() {
var envFileName = ".env"
envFileName := ".env"
flagset := flag.CommandLine
flagset.StringVar(&envFileName, "env", envFileName, "the env file which web app will use to extract its environment variables")

1
_examples/tutorial/url-shortener/main.go

@ -99,7 +99,6 @@ func newApp(db *DB) *iris.Application {
ctx.ViewData("FORM_RESULT",
template.HTML("<pre><a target='_new' href='"+shortenURL+"'>"+shortenURL+" </a></pre>"))
}
}
}

1
_examples/tutorial/url-shortener/main_test.go

@ -73,5 +73,4 @@ func TestURLShortener(t *testing.T) {
}
time.Sleep(1 * time.Second)
}

7
_examples/tutorial/url-shortener/store.go

@ -20,9 +20,7 @@ type Store interface {
Close() // release the store or ignore
}
var (
tableURLs = []byte("urls")
)
var tableURLs = []byte("urls")
// DB representation of a Store.
// Only one table/bucket which contains the urls, so it's not a fully Database,
@ -44,7 +42,7 @@ func openDatabase(stumb string) *bolt.DB {
}
// create the buckets here
var tables = [...][]byte{
tables := [...][]byte{
tableURLs,
}
@ -160,7 +158,6 @@ func (d *DB) GetByValue(value string) (keys []string) {
// Len returns all the "shorted" urls length
func (d *DB) Len() (num int) {
d.db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys
b := tx.Bucket(tableURLs)
if b == nil {

2
_examples/view/overview/main.go

@ -14,11 +14,9 @@ func main() {
// - {{ current }}
app.RegisterView(iris.HTML("./templates", ".html"))
app.Get("/", func(ctx iris.Context) {
ctx.ViewData("Name", "iris") // the .Name inside the ./templates/hi.html
ctx.Gzip(true) // enable gzip for big files
ctx.View("hi.html") // render the template with the file name relative to the './templates'
})
// http://localhost:8080/

1
_examples/view/template_html_3/main.go

@ -59,7 +59,6 @@ func main() {
// http://localhost:8080
// http://localhost:8080/redirect/my-page1
app.Run(iris.Addr(":8080"))
}
func writePathHandler(ctx iris.Context) {

2
_examples/view/template_jet_0/main.go

@ -91,7 +91,7 @@ func main() {
})
app.RegisterView(tmpl) // <--
var todos = map[string]*tTODO{
todos := map[string]*tTODO{
"example-todo-1": {Text: "Add an show todo page to the example project", Done: true},
"example-todo-2": {Text: "Add an add todo page to the example project"},
"example-todo-3": {Text: "Add an update todo page to the example project"},

1
_examples/view/template_pug_0/main.go

@ -25,5 +25,4 @@ func index(ctx iris.Context) {
// Q: why need extension .pug?
// A: Because you can register more than one view engine per Iris application.
ctx.View("index.pug")
}

1
_examples/view/write-to/main.go

@ -34,7 +34,6 @@ func main() {
RefTitle: "Iris web framework",
RefLink: "https://iris-go.com",
})
if err != nil {
app.Logger().Errorf("error from app.View: %v", err)
}

1
cache/browser_test.go

@ -76,6 +76,7 @@ func TestCache304(t *testing.T) {
r = e.GET("/").Expect().Status(httptest.StatusOK)
r.Body().Equal("send")
}
func TestETag(t *testing.T) {
t.Parallel()

3
cache/cache_test.go

@ -104,7 +104,6 @@ func TestClientNoCache(t *testing.T) {
if err := runTest(e, "/", &n, expectedBodyStr, "/nocache"); err != nil {
t.Fatalf(t.Name()+": %v", err)
}
}
func TestCache(t *testing.T) {
@ -136,7 +135,6 @@ func TestCache(t *testing.T) {
if err := runTest(e, "/other", &n2, expectedBodyStr2, ""); err != nil {
t.Fatalf(t.Name()+" other: %v", err)
}
}
func TestCacheHandlerParallel(t *testing.T) {
@ -185,7 +183,6 @@ func TestCacheValidator(t *testing.T) {
atomic.AddUint32(&n, 1)
ctx.Header("DONT", "DO not cache that response even if it was claimed")
ctx.Write([]byte(expectedBodyStr))
})
e := httptest.New(t, app)

1
cache/client/handler.go

@ -168,5 +168,4 @@ func (h *Handler) ServeHTTP(ctx context.Context) {
// fmt.Printf("key: %s\n", key)
// fmt.Printf("write content type: %s\n", response.Headers()["ContentType"])
// fmt.Printf("write body len: %d\n", len(response.Body()))
}

1
cache/client/rule/chained.go

@ -36,7 +36,6 @@ func Chained(rule Rule, next ...Rule) Rule {
}
return c
}
// Claim validator

1
cache/entry/entry.go

@ -101,7 +101,6 @@ func CopyHeaders(dst map[string][]string, src map[string][]string) {
// to re-set the response with the new handler's content result
func (e *Entry) Reset(statusCode int, headers map[string][]string,
body []byte, lifeChanger LifeChanger) {
if e.response == nil {
e.response = &Response{}
}

1
cache/uri/uribuilder.go

@ -71,7 +71,6 @@ func (r URIBuilder) String() string {
}
func (r URIBuilder) build() string {
remoteURL := r.serverAddr
// fasthttp appends the "/" in the last uri (with query args also, that's probably a fasthttp bug which I'll fix later)

1
configuration_test.go

@ -223,7 +223,6 @@ Other:
if expected, got := "Iris: https://github.com/kataras/iris", c.Other["MyServerName"]; expected != got {
t.Fatalf("error on TestConfigurationYAML: Expected Other['MyServerName'] %s but got %s", expected, got)
}
}
func TestConfigurationTOML(t *testing.T) {

24
context/context.go

@ -2110,9 +2110,7 @@ func GetForm(r *http.Request, postMaxMemory int64, resetBody bool) (form map[str
}
}
var (
bodyCopy []byte
)
var bodyCopy []byte
if resetBody {
// on POST, PUT and PATCH it will read the form values from request body otherwise from URL queries.
@ -2360,7 +2358,6 @@ func uploadTo(fh *multipart.FileHeader, destDirectory string) (int64, error) {
out, err := os.OpenFile(filepath.Join(destDirectory, fh.Filename),
os.O_WRONLY|os.O_CREATE, os.FileMode(0666))
if err != nil {
return 0, err
}
@ -2534,7 +2531,7 @@ func (ctx *context) shouldOptimize() bool {
//
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-json/main.go
func (ctx *context) ReadJSON(outPtr interface{}) error {
var unmarshaler = json.Unmarshal
unmarshaler := json.Unmarshal
if ctx.shouldOptimize() {
unmarshaler = jsoniter.Unmarshal
}
@ -2814,9 +2811,7 @@ func (ctx *context) ClientSupportsGzip() bool {
return false
}
var (
errClientDoesNotSupportGzip = errors.New("client doesn't support gzip compression")
)
var errClientDoesNotSupportGzip = errors.New("client doesn't support gzip compression")
// WriteGzip accepts bytes, which are compressed to gzip format and sent to the client.
// returns the number of bytes written and an error ( if the client doesn't support gzip compression)
@ -3163,7 +3158,7 @@ func (ctx *context) JSON(v interface{}, opts ...JSON) (n int, err error) {
if options.StreamingJSON {
if ctx.shouldOptimize() {
var jsoniterConfig = jsoniter.Config{
jsoniterConfig := jsoniter.Config{
EscapeHTML: !options.UnescapeHTML,
IndentionStep: 4,
}.Froze()
@ -3194,9 +3189,7 @@ func (ctx *context) JSON(v interface{}, opts ...JSON) (n int, err error) {
return n, err
}
var (
finishCallbackB = []byte(");")
)
var finishCallbackB = []byte(");")
// WriteJSONP marshals the given interface object and writes the JSON response to the writer.
func WriteJSONP(writer io.Writer, v interface{}, options JSONP, enableOptimization ...bool) (int, error) {
@ -4081,9 +4074,7 @@ func (n *NegotiationAcceptBuilder) EncodingGzip() *NegotiationAcceptBuilder {
// | Serve files |
// +------------------------------------------------------------+
var (
errServeContent = errors.New("while trying to serve content to the client. Trace %s")
)
var errServeContent = errors.New("while trying to serve content to the client. Trace %s")
// ServeContent serves content, headers are autoset
// receives three parameters, it's low-level function, instead you can use .ServeFile(string,bool)/SendFile(string,string)
@ -4387,7 +4378,7 @@ func (ctx *context) Recorder() *ResponseRecorder {
// when the response writer is recording the status code, body, headers and so on,
// else returns nil and false.
func (ctx *context) IsRecording() (*ResponseRecorder, bool) {
//NOTE:
// NOTE:
// two return values in order to minimize the if statement:
// if (Recording) then writer = Recorder()
// instead we do: recorder,ok = Recording()
@ -4435,7 +4426,6 @@ func (ctx *context) BeginTransaction(pipe func(t *Transaction)) {
// give back to the transaction the original writer (SetBeforeFlush works this way and only this way)
// this is tricky but nessecery if we want ctx.FireStatusCode to work inside transactions
t.Context().ResetResponseWriter(ctx.writer)
}()
// run the worker with its context clone inside.

1
context/gzip_response_writer.go

@ -133,7 +133,6 @@ func (w *GzipResponseWriter) WriteString(s string) (n int, err error) {
if w.ResponseWriter.Header()[ContentTypeHeaderKey] == nil {
w.ResponseWriter.Header().Set(ContentTypeHeaderKey, ContentTextHeaderValue)
}
}
return
}

210
context/request_params.go

@ -89,124 +89,122 @@ func (r RequestParams) GetIntUnslashed(key string) (int, bool) {
return -1, false
}
var (
// ParamResolvers is the global param resolution for a parameter type for a specific go std or custom type.
//
// Key is the specific type, which should be unique.
// The value is a function which accepts the parameter index
// and it should return the value as the parameter type evaluator expects it.
// i.e [reflect.TypeOf("string")] = func(paramIndex int) interface{} {
// return func(ctx Context) <T> {
// return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(<T>)
// }
// }
//
// Read https://github.com/kataras/iris/tree/master/_examples/routing/macros for more details.
// Checks for total available request parameters length
// and parameter index based on the hero/mvc function added
// in order to support the MVC.HandleMany("GET", "/path/{ps}/{pssecond} /path/{ps}")
// when on the second requested path, the 'pssecond' should be empty.
ParamResolvers = map[reflect.Type]func(paramIndex int) interface{}{
reflect.TypeOf(""): func(paramIndex int) interface{} {
return func(ctx Context) string {
if ctx.Params().Len() <= paramIndex {
return ""
}
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(string)
// ParamResolvers is the global param resolution for a parameter type for a specific go std or custom type.
//
// Key is the specific type, which should be unique.
// The value is a function which accepts the parameter index
// and it should return the value as the parameter type evaluator expects it.
// i.e [reflect.TypeOf("string")] = func(paramIndex int) interface{} {
// return func(ctx Context) <T> {
// return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(<T>)
// }
// }
//
// Read https://github.com/kataras/iris/tree/master/_examples/routing/macros for more details.
// Checks for total available request parameters length
// and parameter index based on the hero/mvc function added
// in order to support the MVC.HandleMany("GET", "/path/{ps}/{pssecond} /path/{ps}")
// when on the second requested path, the 'pssecond' should be empty.
var ParamResolvers = map[reflect.Type]func(paramIndex int) interface{}{
reflect.TypeOf(""): func(paramIndex int) interface{} {
return func(ctx Context) string {
if ctx.Params().Len() <= paramIndex {
return ""
}
},
reflect.TypeOf(int(1)): func(paramIndex int) interface{} {
return func(ctx Context) int {
if ctx.Params().Len() <= paramIndex {
return 0
}
// v, _ := ctx.Params().GetEntryAt(paramIndex).IntDefault(0)
// return v
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int)
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(string)
}
},
reflect.TypeOf(int(1)): func(paramIndex int) interface{} {
return func(ctx Context) int {
if ctx.Params().Len() <= paramIndex {
return 0
}
},
reflect.TypeOf(int8(1)): func(paramIndex int) interface{} {
return func(ctx Context) int8 {
if ctx.Params().Len() <= paramIndex {
return 0
}
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int8)
// v, _ := ctx.Params().GetEntryAt(paramIndex).IntDefault(0)
// return v
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int)
}
},
reflect.TypeOf(int8(1)): func(paramIndex int) interface{} {
return func(ctx Context) int8 {
if ctx.Params().Len() <= paramIndex {
return 0
}
},
reflect.TypeOf(int16(1)): func(paramIndex int) interface{} {
return func(ctx Context) int16 {
if ctx.Params().Len() <= paramIndex {
return 0
}
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int16)
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int8)
}
},
reflect.TypeOf(int16(1)): func(paramIndex int) interface{} {
return func(ctx Context) int16 {
if ctx.Params().Len() <= paramIndex {
return 0
}
},
reflect.TypeOf(int32(1)): func(paramIndex int) interface{} {
return func(ctx Context) int32 {
if ctx.Params().Len() <= paramIndex {
return 0
}
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int32)
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int16)
}
},
reflect.TypeOf(int32(1)): func(paramIndex int) interface{} {
return func(ctx Context) int32 {
if ctx.Params().Len() <= paramIndex {
return 0
}
},
reflect.TypeOf(int64(1)): func(paramIndex int) interface{} {
return func(ctx Context) int64 {
if ctx.Params().Len() <= paramIndex {
return 0
}
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int64)
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int32)
}
},
reflect.TypeOf(int64(1)): func(paramIndex int) interface{} {
return func(ctx Context) int64 {
if ctx.Params().Len() <= paramIndex {
return 0
}
},
reflect.TypeOf(uint(1)): func(paramIndex int) interface{} {
return func(ctx Context) uint {
if ctx.Params().Len() <= paramIndex {
return 0
}
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint)
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(int64)
}
},
reflect.TypeOf(uint(1)): func(paramIndex int) interface{} {
return func(ctx Context) uint {
if ctx.Params().Len() <= paramIndex {
return 0
}
},
reflect.TypeOf(uint8(1)): func(paramIndex int) interface{} {
return func(ctx Context) uint8 {
if ctx.Params().Len() <= paramIndex {
return 0
}
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint8)
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint)
}
},
reflect.TypeOf(uint8(1)): func(paramIndex int) interface{} {
return func(ctx Context) uint8 {
if ctx.Params().Len() <= paramIndex {
return 0
}
},
reflect.TypeOf(uint16(1)): func(paramIndex int) interface{} {
return func(ctx Context) uint16 {
if ctx.Params().Len() <= paramIndex {
return 0
}
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint16)
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint8)
}
},
reflect.TypeOf(uint16(1)): func(paramIndex int) interface{} {
return func(ctx Context) uint16 {
if ctx.Params().Len() <= paramIndex {
return 0
}
},
reflect.TypeOf(uint32(1)): func(paramIndex int) interface{} {
return func(ctx Context) uint32 {
if ctx.Params().Len() <= paramIndex {
return 0
}
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint32)
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint16)
}
},
reflect.TypeOf(uint32(1)): func(paramIndex int) interface{} {
return func(ctx Context) uint32 {
if ctx.Params().Len() <= paramIndex {
return 0
}
},
reflect.TypeOf(uint64(1)): func(paramIndex int) interface{} {
return func(ctx Context) uint64 {
if ctx.Params().Len() <= paramIndex {
return 0
}
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint64)
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint32)
}
},
reflect.TypeOf(uint64(1)): func(paramIndex int) interface{} {
return func(ctx Context) uint64 {
if ctx.Params().Len() <= paramIndex {
return 0
}
},
reflect.TypeOf(true): func(paramIndex int) interface{} {
return func(ctx Context) bool {
if ctx.Params().Len() <= paramIndex {
return false
}
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(bool)
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(uint64)
}
},
reflect.TypeOf(true): func(paramIndex int) interface{} {
return func(ctx Context) bool {
if ctx.Params().Len() <= paramIndex {
return false
}
},
}
)
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(bool)
}
},
}
// ParamResolverByTypeAndIndex will return a function that can be used to bind path parameter's exact value by its Go std type
// and the parameter's index based on the registered path.

1
context/response_recorder.go

@ -188,7 +188,6 @@ func (w *ResponseRecorder) Clone() ResponseWriter {
// WriteTo writes a response writer (temp: status code, headers and body) to another response writer
func (w *ResponseRecorder) WriteTo(res ResponseWriter) {
if to, ok := res.(*ResponseRecorder); ok {
// set the status code, to is first ( probably an error? (context.StatusCodeNotSuccessful, defaults to < 200 || >= 400).

1
context/response_writer.go

@ -298,7 +298,6 @@ func (w *responseWriter) WriteTo(to ResponseWriter) {
}
}
}
}
// the body is not copied, this writer doesn't support recording
}

6
core/errors/errors.go

@ -8,10 +8,8 @@ import (
"github.com/iris-contrib/go.uuid"
)
var (
// Prefix the error prefix, applies to each error's message.
Prefix = ""
)
// Prefix the error prefix, applies to each error's message.
var Prefix = ""
// Error holds the error message, this message never really changes
type Error struct {

2
core/errors/errors_test.go

@ -14,7 +14,6 @@ var userMail = "user1@mail.go"
var expectedUserAlreadyExists = "User with mail: user1@mail.go already exists"
func ExampleError() {
fmt.Print(errUserAlreadyExists.Format(userMail).Append("Please change your mail addr"))
// Output:
@ -38,7 +37,6 @@ func TestFormat(t *testing.T) {
}
func TestAppendErr(t *testing.T) {
errChangeMailMsg := "Please change your mail addr"
errChangeMail := fmt.Errorf(errChangeMailMsg) // test go standard error
errAppended := errUserAlreadyExists.AppendErr(errChangeMail)

1
core/errors/reporter.go

@ -78,7 +78,6 @@ func (r *Reporter) AddErr(err error) bool {
//
// Returns true if this "err" is not nil and it's added to the reporter's stack.
func (r *Reporter) Add(format string, a ...interface{}) bool {
if format == "" && len(a) == 0 {
return false
}

3
core/handlerconv/from_std.go

@ -26,7 +26,7 @@ func FromStd(handler interface{}) context.Handler {
case context.Handler:
{
//
//it's already a iris handler
// it's already a iris handler
//
return handler.(context.Handler)
}
@ -67,7 +67,6 @@ func FromStd(handler interface{}) context.Handler {
}
}
}
// FromStdWithNext receives a standar handler - middleware form - and returns a

1
core/handlerconv/from_std_test.go

@ -36,7 +36,6 @@ func TestFromStd(t *testing.T) {
}
func TestFromStdWithNext(t *testing.T) {
basicauth := "secret"
passed := "ok"

1
core/host/supervisor_task_example_test.go

@ -76,7 +76,6 @@ func (m myTestTask) OnServe(host TaskHost) {
time.AfterFunc(startDelay, func() {
m.logger.Println("restart")
host.Serve() // restart
})
}

7
core/host/supervisor_test.go

@ -20,7 +20,6 @@ const (
)
func newTester(t *testing.T, baseURL string, handler http.Handler) *httpexpect.Expect {
var transporter http.RoundTripper
if strings.HasPrefix(baseURL, "http") { // means we are testing real serve time
@ -57,9 +56,8 @@ func testSupervisor(t *testing.T, creator func(*http.Server, []func(TaskHost)) *
)
// http routing
var (
expectedBody = "this is the response body\n"
)
expectedBody := "this is the response body\n"
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
@ -98,6 +96,7 @@ func testSupervisor(t *testing.T, creator func(*http.Server, []func(TaskHost)) *
t.Fatalf("expected hello Task's message to be '%s' but got '%s'", expectedHelloMessage, got)
}
}
func TestSupervisor(t *testing.T) {
testSupervisor(t, func(srv *http.Server, tasks []func(TaskHost)) *Supervisor {