1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-24 04:15:56 +00:00

formatting

Former-commit-id: 037081db5d6d4434e873ca8b75334ee43e046b6a
This commit is contained in:
Gerasimos (Makis) Maropoulos
2019-08-17 10:06:20 +03:00
parent 00967408dc
commit 07046ab978
112 changed files with 477 additions and 517 deletions

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -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",

View File

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

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -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())

View File

@@ -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)

View File

@@ -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))
}

View File

@@ -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>")

View File

@@ -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
}

View File

@@ -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)
}
}

View File

@@ -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",

View File

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

View File

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

View File

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

View File

@@ -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())

View File

@@ -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)
}

View File

@@ -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{

View File

@@ -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.")

View File

@@ -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)
}

View File

@@ -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) {

View File

@@ -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"),

View File

@@ -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"))
}

View File

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

View File

@@ -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)
})

View File

@@ -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)
})

View File

@@ -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)
})

View File

@@ -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) {

View File

@@ -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)

View File

@@ -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:

View File

@@ -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)
}
}

View File

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

View File

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

View File

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

View File

@@ -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())

View File

@@ -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")

View File

@@ -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>"))
}
}
}

View File

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

View File

@@ -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 {

View File

@@ -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/

View File

@@ -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) {

View File

@@ -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"},

View File

@@ -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")
}

View File

@@ -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)
}