Skip to content

Instantly share code, notes, and snippets.

View madflojo's full-sized avatar
:octocat:
Writing code that might be useful

Benjamin Cane madflojo

:octocat:
Writing code that might be useful
View GitHub Profile
@madflojo
madflojo / client-output.console
Created September 5, 2021 18:22
Set Linger - First Client Output
$ go run client.go
2021/09/05 11:17:12 TCP Session Open
2021/09/05 11:17:27 Error from TCP Session: EOF
exit status 1
@madflojo
madflojo / server_logs.console
Created September 5, 2021 18:17
Set Linger Article - First Server Logs
$ go run main.go
2021/09/05 11:17:12 TCP Session Open
2021/09/05 11:17:27 Error reading TCP Session: read tcp [::1]:9000->[::1]:50770: use of closed network connection
@madflojo
madflojo / client.go
Created September 1, 2021 14:43
SetLinger Article - TCP Client
package main
import (
"log"
"net"
)
func main() {
// Open a TCP Session to Server
c, err := net.Dial("tcp", "localhost:9000")
@madflojo
madflojo / main-linger.go
Created September 1, 2021 14:42
SetLinger Article - TCP Server with SetLinger
package main
import (
"log"
"net"
"time"
)
func main() {
// Create a listener
@madflojo
madflojo / main.go
Last active September 3, 2021 02:23
SetLinger Article - Basic TCP Server
package main
import (
"log"
"net"
"time"
)
func main() {
// Create a listener
@madflojo
madflojo / http-middleware-pprof-full.go
Created August 5, 2021 02:48
httprouter Article - Middleware with PProf full
package main
import (
"fmt"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
"net/http/pprof"
)
@madflojo
madflojo / http-middleware-pprof.go
Created August 4, 2021 02:42
httprouter Article - Registering PProf Index
package main
import (
"fmt"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
"net/http/pprof"
)
@madflojo
madflojo / http-middleware.go
Created August 1, 2021 03:42
httprouter Article - Hello World with Middleware
package main
import (
"fmt"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
)
// handler is a basic HTTP handler that prints hello world.
@madflojo
madflojo / httprouter-params.go
Last active August 1, 2021 02:12
httprouter Article - Parameterized Handler
// handler is a basic HTTP handler that prints hello world.
func handler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "Hello %s", ps.ByName("name"))
}
@madflojo
madflojo / httprouter.go
Created July 31, 2021 03:52
httprouter Article - Basic HTTP Example (w/httprouter)
package main
import (
"fmt"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
)
// handler is a basic HTTP handler that prints hello world.