Go to file
Renovate 692390488e
ci/woodpecker/push/test Pipeline was successful Details
chore(deps): update golangci/golangci-lint docker tag to v1.57 (#10)
Reviewed-on: #10
Co-authored-by: Renovate <renovate@dwysokinski.me>
Co-committed-by: Renovate <renovate@dwysokinski.me>
2024-03-30 04:43:32 +00:00
.woodpecker chore(deps): update golangci/golangci-lint docker tag to v1.57 (#10) 2024-03-30 04:43:32 +00:00
.gitignore init 2023-05-12 06:54:44 +02:00
.golangci.yml feat: migrate from drone to woodpecker 2023-08-20 07:26:31 +02:00
LICENSE init 2023-05-12 06:54:44 +02:00
README.md chore: update README.md [CI SKIP] 2023-08-20 07:28:04 +02:00
client_ip.go fix: fix linter errors 2023-05-12 06:56:51 +02:00
client_ip_test.go refactor: remove redundant http.CanonicalHeaderKey 2023-05-12 08:09:49 +02:00
go.mod chore(deps): update module github.com/stretchr/testify to v1.9.0 (#12) 2024-03-02 05:38:57 +00:00
go.sum chore(deps): update module github.com/stretchr/testify to v1.9.0 (#12) 2024-03-02 05:38:57 +00:00
renovate.json chore: add renovate.json [skip ci] 2023-05-12 06:59:33 +02:00

README.md

chiclientip Build Status

Getting started

Installation

go get gitea.dwysokinski.me/Kichiyaki/chiclientip

Usage

package main

import (
	"log"
	"net/http"

	"gitea.dwysokinski.me/Kichiyaki/chiclientip"
	"github.com/go-chi/chi/v5"
	"github.com/realclientip/realclientip-go"
)

func main() {
	stratXForwardedFor, err := realclientip.NewRightmostNonPrivateStrategy("X-Forwarded-For")
	if err != nil {
		log.Fatalln("realclientip.NewRightmostNonPrivateStrategy", err)
	}
	strat := realclientip.NewChainStrategy(
		stratXForwardedFor,
		realclientip.RemoteAddrStrategy{},
	)

	router := chi.NewRouter()
	router.Use(chiclientip.ClientIP(strat))
	router.Get("/", func(w http.ResponseWriter, r *http.Request) {
		clientIP, _ := chiclientip.ClientIPFromContext(r.Context())
		_, _ = w.Write([]byte(clientIP))
	})

	http.ListenAndServe(":8080", router)
}

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Dawid Wysokiński - contact@dwysokinski.me