# Slide

## Full length example

```go
package main

import (
	"fmt"
	"github.com/go-slide/slide/middleware"
	"log"
	"net/http"

	"github.com/go-slide/slide"

	"github.com/go-playground/validator/v10"
)

type Login struct {
	Username string `json:"username" validate:"required"`
	Password string `json:"password" validate:"required"`
}


func main() {
	validate := validator.New()
	config := slide.Config{
		Validator: validate,
	}

	app := slide.InitServer(&config)

	// compression middleware
	app.Use(middleware.Compress())

	// this is with config
	app.Use(middleware.CorsWithConfig(middleware.CorsConfig{
		AllowOrigins: []string{"https://www.postgresqltutorial.com"},
	}))

	// you can multiple middlewares also
	app.Use(func(ctx *slide.Ctx) error {
		fmt.Println("this will run for all URL(s)")
		return ctx.Next()
	})

	app.Get("/", func(ctx *slide.Ctx) error {
		return ctx.Send(http.StatusOK, "Hello, World")
	})

	// redirect to new url
	app.Get("/redirect", func(ctx *slide.Ctx) error {
		return ctx.Redirect(http.StatusTemporaryRedirect, "http://localhost:3000/static")
	})

	app.Get("/name/:name", func(ctx *slide.Ctx) error {
		name := ctx.GetParam("name")
		return ctx.Send(http.StatusOK, fmt.Sprintf("hello, %s", name))
	})

	app.Post("/login", func(ctx *slide.Ctx) error {
		login := Login{}
		err := ctx.Bind(&login)
		if err != nil {
			return err
		}
		return ctx.Json(http.StatusOK, map[string]string{
			"message": fmt.Sprintf("Welcome %s", login.Username),
		})
	})

	// Grouping your route
	auth := app.Group("/auth")
	// you can multiple middlewares also
	auth.Use(func(ctx *slide.Ctx) error {
		fmt.Println("this will run for all urls with /auth")
		return ctx.Next()
	})
	auth.Get("/login", func(ctx *slide.Ctx) error {
		return ctx.Send(http.StatusOK, "Hello, World")
	})

	// path and dir name
	app.ServerDir("/static", "static")

	// single file
	app.ServeFile("/js", "static/login.js")

	// Downloading file
	app.Get("/download", func(ctx *slide.Ctx) error {
		return ctx.SendAttachment("static/login.js", "login.js")
	})

	// uploading file
	app.Post("/upload", func(ctx *slide.Ctx) error {
		return ctx.UploadFile("static/login.js", "login.js")
	})

	log.Fatal(app.Listen("localhost:3000"))
}
```

Becoming a super hero is a fairly straight forward process:

```
$ give me super-powers
```

{% hint style="info" %}
&#x20;Super-powers are granted randomly so please submit an issue if you're not happy with yours.
{% endhint %}

Once you're strong enough, save the world:

{% code title="hello.sh" %}

```bash
# Ain't no code for that yet, sorry
echo 'You got to trust me on this, I saved the world'
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://goslide-framework.gitbook.io/slide/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
