From 5d4761c835ff3173d6324b14525f43bb0e7e5af3 Mon Sep 17 00:00:00 2001 From: Max Napedenin Date: Mon, 9 Jan 2023 19:52:21 +0400 Subject: [PATCH] #Improve: Use more preferable way to specify logger - Interface to have posability pass any logger such as zap.Logger by using Adapter pattern. --- go.mod | 2 +- options.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 55d2b76..03d4013 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/alexandrevicenzi/go-sse -go 1.11 +go 1.18 diff --git a/options.go b/options.go index fe67dc8..534749e 100644 --- a/options.go +++ b/options.go @@ -1,10 +1,16 @@ package sse import ( - "log" "net/http" ) +// Logger Interface with all necessary functions to log. +type LogPrinter interface { + Print(v ...any) + Println(v ...any) + Printf(format string, v ...any) +} + // Options holds server configurations. type Options struct { // RetryInterval change EventSource default retry interval (milliseconds). @@ -15,7 +21,7 @@ type Options struct { // Default channel name is the request path. ChannelNameFunc func(*http.Request) string // All usage logs end up in Logger - Logger *log.Logger + Logger LogPrinter } func (opt *Options) hasHeaders() bool {