🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

webimizer.dev/webimizer

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webimizer.dev/webimizer

Go Modules
Version
v1.2.0
Version published
Created
Source

webimizer

Lightweight HTTP framework module written in Go

Code example

package main

import (
	"fmt"
	"log"
	"net/http"

	app "webimizer.dev/webimizer"
)

func httpNotAllowFunc(rw http.ResponseWriter, r *http.Request) {
	rw.WriteHeader(http.StatusBadRequest)
	fmt.Fprint(rw, "Bad Request")
}

func main() {
	app.DefaultHTTPHeaders = [][]string{
		{"x-content-type-options", "nosniff"},
		{"x-frame-options", "SAMEORIGIN"},
		{"x-xss-protection", "1; mode=block"},
	} // define default headers
	http.Handle("/", app.HttpHandlerStruct{
		Handler: app.HttpHandler(func(rw http.ResponseWriter, r *http.Request) {
			app.Get(rw, r, func(rw http.ResponseWriter, r *http.Request) {
				fmt.Fprint(rw, "Hello from webimizer. HTTP GET method was used.")
			})
			app.Post(rw, r, func(rw http.ResponseWriter, r *http.Request) {
				fmt.Fprint(rw, "Hello from webimizer. HTTP POST method was used.")
			})
		}), // app.HttpHandler call only if method is allowed
		NotAllowHandler: app.HttpNotAllowHandler(httpNotAllowFunc), // app.HtttpNotAllowHandler call if method is not allowed
		AllowedMethods:  []string{"GET","POST"},                           // define allowed methods
	}.Build())
	log.Fatal(http.ListenAndServe(":8080", nil)) // example server listen on port 8080
}

FAQs

Package last updated on 11 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts