Log Connections #10

Open
opened 2020-06-27 02:30:27 +00:00 by 62726164 · 4 comments
62726164 commented 2020-06-27 02:30:27 +00:00 (Migrated from github.com)

Given this code, what would be the best way to log client IPs as they connect to the server?

package main

import (
        "github.com/prologic/go-gopher"
        "log"
)

func main() {
        gopher.Handle("/", gopher.FileServer(gopher.Dir(".")))
        log.Fatal(gopher.ListenAndServe("0.0.0.0:7070", nil))
}
Given this code, what would be the best way to log client IPs as they connect to the server? ``` package main import ( "github.com/prologic/go-gopher" "log" ) func main() { gopher.Handle("/", gopher.FileServer(gopher.Dir("."))) log.Fatal(gopher.ListenAndServe("0.0.0.0:7070", nil)) } ```

The design of this library is almost identical to that of net/http. So you'd need to write a middleware to wrap your handler. Does this help? If you can do this I'd love a PR that adds a middleware/ sub-package. Otherwise I'll try to find some time to do this...

The design of this library is almost identical to that of `net/http`. So you'd need to write a middleware to wrap your handler. Does this help? If you can do this I'd love a PR that adds a middleware/ sub-package. Otherwise I'll try to find some time to do this...
62726164 commented 2020-06-29 11:25:43 +00:00 (Migrated from github.com)

Thank you, yes, that helps. I'll write it sometime and let you know.

Thank you, yes, that helps. I'll write it sometime and let you know.

The attached patch adds a RemoteAddr field to the gopher.Request, similar to http.Request.

I was unable to push to a fork of the repo on this server, so git format-patch it is. Alternatively, it is available from my repo (the remote-add branch).

As for an example usage, see markdown-gopher (again, using the remote-add branch).

The attached patch adds a `RemoteAddr` field to the `gopher.Request`, similar to `http.Request`. I was unable to push to a fork of the repo on this server, so `git format-patch` it is. Alternatively, it is available from [my repo](https://src.alexschroeder.ch/go-gopher.git/) (the `remote-add` branch). As for an example usage, see [markdown-gopher](https://src.alexschroeder.ch/markdown-gopher.git/) (again, using the `remote-add` branch).

@kensanata Thanks! Will apply this shortly. Sorry for the delay, work and all, been busy 🤣

@kensanata Thanks! Will apply this shortly. Sorry for the delay, work and all, been busy 🤣
Sign in to join this conversation.
No Milestone
No project
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: prologic/go-gopher#10
No description provided.