Categorygithub.com/swayedev/way
modulepackage
0.4.0-rc0
Repository: https://github.com/swayedev/way.git
Documentation: pkg.go.dev

# README

Way Framework

Way Mascot

Go Reference

Version: 0.3.0-rc0

Note. Currently there is no stable version of Way during it's inital development. Do not use this project in it's current state, please wait until a version number committed is higher than or equal to 1.0.0

Overview

Way is a lightweight, Go-based web framework that integrates with the Gorilla Mux router and provides simplified mechanisms for handling HTTP requests inspired by the echo frameworkwhile adding database operations.

Features

  • Custom context for HTTP handlers
  • Simplified route declaration (GET, POST, PUT, DELETE, etc.)
  • Integrated SQL database operations
  • Graceful shutdown and startup management

Getting Started

Installation

To start using the Way framework, install it using go get:

go get -u github.com/swayedev/way

Basic Usage

Here's a simple example to get you started:

package main

import (
    "github.com/swayedev/way"
)

func main() {
    w := way.New()

    w.GET("/", func(ctx *way.Context) {
        ctx.Response.Write([]byte("Hello, World!"))
    })

    w.Start(":8080")
}

Or with a handler function

package main

import "github.com/swayedev/way"

func main() {
	w := way.New()
	w.GET("/", helloHandler)

	w.Start(":8080")
}

func helloHandler(c *way.Context) {
	c.Response.Header().Set("Content-Type", "application/json")
	c.Response.Write([]byte("Hello World"))
}

Routing

Way simplifies route handling with predefined methods for standard HTTP verbs:

w.GET("/path", yourGetHandler)
w.POST("/path", yourPostHandler)
// ... and so on for PUT, DELETE, PATCH, OPTIONS, HEAD

Database Operations

Passing an existing sql db

This section explains how to pass an existing SQL database to the application. It provides instructions and guidelines on how to configure the application to use an existing database instead of creating a new one.



Opening a Connection

err := w.SqlOpen()
if err != nil {
    // Handle error
}

Executing Queries

result, err := w.SqlExec(context.Background(), "your SQL query here", args...)
if err != nil {
    // Handle error
}

Querying Data

rows, err := w.SqlQuery(context.Background(), "your SQL query here", args...)
if err != nil {
    // Handle error
}
// Remember to close rows

Graceful Shutdown

To gracefully shut down your server:

err := w.Shutdown(context.Background())
if err != nil {
    // Handle error
}

Contributing

Contributions to the Way framework are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
GetEnv retrieves the environment variable value or a default value if not set.
New creates a new instance of Way.
No description provided by the author
New initializes a new DB instance.
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Response is the standard go HTTP response writer.
DB struct to handle both sql.DB and pgx.Conn.
defaultStore is the name of the default session store.
No description provided by the author

# Type aliases

HandlerFunc is a function type that represents a handler for a request.
MiddlewareFunc represents a function that takes a HandlerFunc and returns a modified HandlerFunc.