-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cmd: support filtering for multiple dependencies of service log command. a part of #337 fixes a part of #426
- Loading branch information
Showing
11 changed files
with
971 additions
and
102 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package api | ||
|
||
import "github.com/mesg-foundation/core/service" | ||
|
||
// ServiceLogsFilter is a filter func for filtering service logs. | ||
type ServiceLogsFilter func(*logLogger) | ||
|
||
// ServiceLogsDependenciesFilter returns a dependency filter. | ||
func ServiceLogsDependenciesFilter(dependencies ...string) ServiceLogsFilter { | ||
return func(s *logLogger) { | ||
s.dependencies = dependencies | ||
} | ||
} | ||
|
||
// ServiceLogs gives logs for all dependencies or one when specified with filters of service serviceID. | ||
func (a *API) ServiceLogs(serviceID string, filters ...ServiceLogsFilter) ([]*service.Logs, error) { | ||
return newLogLogger(a, filters...).logs(serviceID) | ||
} |
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,34 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/mesg-foundation/core/database/services" | ||
"github.com/mesg-foundation/core/service" | ||
) | ||
|
||
// logLogger provides functionalities to get service logs. | ||
type logLogger struct { | ||
// dependencies used to get only logs from requested dependencies. | ||
dependencies []string | ||
|
||
api *API | ||
} | ||
|
||
// newLogLogger creates a new logLogger with given api and dependency filters. | ||
func newLogLogger(api *API, filters ...ServiceLogsFilter) *logLogger { | ||
l := &logLogger{ | ||
api: api, | ||
} | ||
for _, filter := range filters { | ||
filter(l) | ||
} | ||
return l | ||
} | ||
|
||
// logs gives logs of service serviceID and applies dependency filters to filter logs. | ||
func (l *logLogger) logs(serviceID string) ([]*service.Logs, error) { | ||
s, err := services.Get(serviceID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.Logs(l.dependencies...) | ||
} |
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.