GithubHelp home page GithubHelp logo

kassner / go-fiber-flash-session Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sujit-baniya/flash

0.0 0.0 0.0 26 KB

sujit-baniya/flash but store messages in session

License: MIT License

Go 100.00%

go-fiber-flash-session's Introduction

Set flash message for routes.

This package is build to send the flash messages on the top of Gofiber

Note This is a drop-in replacement for github.com/sujit-baniya/flash which uses the Session middleware instead of cookies.

Installation

The package can be used to validate the data and send flash message to other route.

github.com/kassner/go-fiber-flash-session

Usage

package main

import (
	"github.com/gofiber/fiber/v2"
	"github.com/kassner/go-fiber-flash-session"
)

func main() {
	app := fiber.New()
	app.Get("/success-redirect", func(c *fiber.Ctx) error {
		return c.JSON(flash.Get(c))
	})

	app.Get("/error-redirect", func(c *fiber.Ctx) error {
		flash.Get(c)
		return c.JSON(flash.Get(c))
	})

	app.Get("/error", func(c *fiber.Ctx) error {
		mp := fiber.Map{
			"error":   true,
			"message": "I'm receiving error with inline error data",
		}
		return flash.WithError(c, mp).Redirect("/error-redirect")
	})

	app.Get("/success", func(c *fiber.Ctx) error {
		mp := fiber.Map{
			"success": true,
			"message": "I'm receiving success with inline success data",
		}
		return flash.WithSuccess(c, mp).Redirect("/success-redirect")
	})

	app.Get("/data", func(c *fiber.Ctx) error {
		mp := fiber.Map{
			"text": "Received arbitrary data",
		}
		return flash.WithData(c, mp).Redirect("/success-redirect")
	})

	app.Listen(":8080")
}

go-fiber-flash-session's People

Contributors

kassner avatar sujit-baniya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.