httpStaticRoute

package module
v0.0.0-...-5811269 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2021 License: MIT Imports: 7 Imported by: 0

README

go-http-static-route

Simple Go module for making net/http static routes.

This module preloads all static files on the memory!

usage

Grab the module

go get github.com/lucie-cupcakes/go-http-static-route

Add it to your code:

package main

import (
	"log"
	"net/http"
	httpStaticRoute "github.com/lucie-cupcakes/go-http-static-route"
)

func main() {
	staticFiles, err := httpStaticRoute.LoadStaticFiles("./www",
	func(filePath string) bool {
		return true
	})
	if err != nil {
		panic(err)
	}
	httpStaticRoute.AddStaticRoutes(staticFiles)
	log.Fatal(http.ListenAndServe(":8000", nil))
}

Enjoy!

beta software

This project is in heavy development, please use with caution on production.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddStaticRoutes

func AddStaticRoutes(staticFiles *map[string]*StaticFile)

func LoadStaticFiles

func LoadStaticFiles(dirPath string,
	filterFilePath func(filePath string) bool) (*map[string]*StaticFile, error)

Types

type StaticFile

type StaticFile struct {
	Contents    []byte
	Path        string
	ContentType string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL