-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from ivixvi/add-logger
Add logger
- Loading branch information
Showing
16 changed files
with
156 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,8 @@ jobs: | |
|
||
- name: Test | ||
run: go test -v ./... | ||
|
||
- name: Build example server | ||
run: | | ||
cd ./_example && \ | ||
go build ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import "log" | ||
|
||
type PatcherLogger struct { | ||
logger *log.Logger | ||
} | ||
|
||
func newLogger(logger *log.Logger) PatcherLogger { | ||
return PatcherLogger{ | ||
logger: logger, | ||
} | ||
} | ||
|
||
func (l PatcherLogger) Error(args ...interface{}) { | ||
l.logger.Println(args...) | ||
} | ||
|
||
func (l PatcherLogger) Debug(args ...interface{}) { | ||
l.logger.Println(args...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package scimpatch | ||
|
||
import "context" | ||
|
||
type PatcherLogger interface { | ||
Error(args ...interface{}) | ||
Debug(args ...interface{}) | ||
} | ||
|
||
type noopPatcherLogger struct{} | ||
|
||
func (l noopPatcherLogger) Error(args ...interface{}) {} | ||
func (l noopPatcherLogger) Debug(args ...interface{}) {} | ||
|
||
var noop = noopPatcherLogger{} | ||
|
||
type loggerKey struct{} | ||
|
||
// key is the context key for the logger. | ||
var key = loggerKey{} | ||
|
||
// AddLogger adds a logger to the context. | ||
// If the context already has a logger, AddLogger will overwrite it. | ||
// If the logger is nil, AddLogger will add a no-op logger. | ||
// The logger used by the Patcher. | ||
func AddLogger(ctx context.Context, logger PatcherLogger) context.Context { | ||
return context.WithValue(ctx, key, logger) | ||
} | ||
|
||
func getLogger(ctx context.Context) PatcherLogger { | ||
l, ok := ctx.Value(key).(PatcherLogger) | ||
if !ok { | ||
return noop | ||
} | ||
return l | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
package scimpatch | ||
|
||
import "github.com/scim2/filter-parser/v2" | ||
import ( | ||
"context" | ||
|
||
"github.com/scim2/filter-parser/v2" | ||
) | ||
|
||
// Operator は Patch Operation の各操作のドメインとなるインターフェースです。 | ||
// Direct は map とその map 内で更新対象となる属性と更新後の値を受け取って更新後のmapと変更有無を返却します | ||
// この関数のみ、pathが未指定の場合でも利用されます | ||
// ByValueExpressionForItem は 対象の属性が、MultiValuedComplexAttribute で path にて valFilter が指定されているときにそれを受けとって更新後のスライスと変更有無を返却します。 | ||
// ByValueExpressionForAttribute は 対象の属性が、MultiValuedComplexAttribute で path にて valFilter と subAttr が指定されているときにそれを受けとって更新後のスライスと変更有無を返却します。 | ||
type Operator interface { | ||
Direct(scopedMap map[string]interface{}, scopedAttr string, value interface{}) bool | ||
|
||
ByValueExpressionForItem(scopedMaps []map[string]interface{}, expr filter.Expression, value interface{}) ([]map[string]interface{}, bool) | ||
ByValueExpressionForAttribute(scopedMaps []map[string]interface{}, expr filter.Expression, subAttr string, value interface{}) ([]map[string]interface{}, bool) | ||
Direct(ctx context.Context, scopedMap map[string]interface{}, scopedAttr string, value interface{}) bool | ||
ByValueExpressionForItem(ctx context.Context, scopedMaps []map[string]interface{}, expr filter.Expression, value interface{}) ([]map[string]interface{}, bool) | ||
ByValueExpressionForAttribute(ctx context.Context, scopedMaps []map[string]interface{}, expr filter.Expression, subAttr string, value interface{}) ([]map[string]interface{}, bool) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.