Skip to content

Commit

Permalink
chore: go 1.19, replace interface{} with any
Browse files Browse the repository at this point in the history
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
  • Loading branch information
rustatian committed Aug 4, 2022
1 parent 6452504 commit fcd3f6d
Show file tree
Hide file tree
Showing 44 changed files with 110 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: true
matrix:
go: [ 1.18 ]
go: [ 1.19 ]
os: [ ubuntu-latest ]
env:
GO111MODULE: on
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: true
matrix:
go: [ 1.18 ]
go: [ 1.19 ]
os: [ macos-latest ]
env:
GO111MODULE: on
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: true
matrix:
go: [ 1.18 ]
go: [ 1.19 ]
os: [ windows-latest ]
env:
GO111MODULE: on
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ type (

// Provider declares the ability to provide dependencies to other plugins (OPTIONAL)
Provider interface {
Provides() []interface{}
Provides() []any
}

// Collector declares the ability to accept the plugins which match the provided method signature (OPTIONAL)
Collector interface {
Collects() []interface{}
Collects() []any
}
)

Expand Down
2 changes: 1 addition & 1 deletion docs/endure_arch.drawio
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<mxCell id="HHnZ4qpc_pkSZuf3FhQu-26" value="" style="line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;fontSize=15;fontColor=#000000;fontFamily=Jetbrains Mono;" parent="HHnZ4qpc_pkSZuf3FhQu-21" vertex="1">
<mxGeometry y="52" width="290" height="8" as="geometry" />
</mxCell>
<mxCell id="HHnZ4qpc_pkSZuf3FhQu-23" value="Iface interface{}" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontSize=14;fontStyle=0;fontFamily=Jetbrains Mono;" parent="HHnZ4qpc_pkSZuf3FhQu-21" vertex="1">
<mxCell id="HHnZ4qpc_pkSZuf3FhQu-23" value="Iface any" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontSize=14;fontStyle=0;fontFamily=Jetbrains Mono;" parent="HHnZ4qpc_pkSZuf3FhQu-21" vertex="1">
<mxGeometry y="60" width="290" height="26" as="geometry" />
</mxCell>
<mxCell id="HHnZ4qpc_pkSZuf3FhQu-25" value="" style="line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;fontSize=15;fontColor=#000000;fontFamily=Jetbrains Mono;" parent="HHnZ4qpc_pkSZuf3FhQu-21" vertex="1">
Expand Down
6 changes: 3 additions & 3 deletions examples/sample_1/modules/http/http_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"time"

"github.com/gorilla/mux"
"github.com/rs/cors"
"github.com/roadrunner-server/endure/examples/db_http_logger/modules/db"
"github.com/roadrunner-server/endure/examples/db_http_logger/modules/logger"
"github.com/rs/cors"
)

type Http struct {
Expand Down Expand Up @@ -100,8 +100,8 @@ func (h *Http) Stop() error {
return nil
}

func (h *Http) Collects() []interface{} {
return []interface{}{
func (h *Http) Collects() []any {
return []any{
h.AddMiddleware,
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/sample_1/modules/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func (l *Logger) Init() error {
return nil
}

func (l *Logger) Provides() []interface{} {
return []interface{}{
func (l *Logger) Provides() []any {
return []any{
l.LoggerInstance,
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/roadrunner-server/endure

go 1.18
go 1.19

require (
github.com/roadrunner-server/errors v1.1.2
Expand Down
8 changes: 3 additions & 5 deletions pkg/container/calculate_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Adds a provided type via the Provider interface:
actual type after FnsProviderToInvoke will be invoked
2. FnsProviderToInvoke --> is the list of the functions to invoke via the reflection to get the actual provided type
*/
func (e *Endure) addProviders(vertexID string, vertex interface{}) error {
func (e *Endure) addProviders(vertexID string, vertex any) error {
// hot path
if _, ok := vertex.(Provider); !ok {
return nil
Expand All @@ -27,7 +27,7 @@ func (e *Endure) addProviders(vertexID string, vertex interface{}) error {
}

// vertex implements provider
func (e *Endure) implProvidesPath(vertexID string, vrtx interface{}) error {
func (e *Endure) implProvidesPath(vertexID string, vrtx any) error {
const op = errors.Op("endure_add_providers")
provider := vrtx.(Provider)
for _, fn := range provider.Provides() {
Expand Down Expand Up @@ -125,11 +125,9 @@ structs) in the function parameters list.
If we found such vertex we can go by the following paths:
1. Function parameters list contain interfaces
2. Function parameters list contain only structures (easy case)
*/
func (e *Endure) implCollectorPath(vrtx *vertex.Vertex) error {
// vertexID string, vertex interface{} same vertex
// vertexID string, vertex any same vertex
const op = errors.Op("endure_impl_collector_path")
collector := vrtx.Iface.(Collector)
// range Collectors functions
Expand Down
8 changes: 4 additions & 4 deletions pkg/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ type (
// Stop stops the plugins in rev-topological order
Stop() error
// Register registers one plugin in container
Register(service interface{}) error
Register(service any) error
// RegisterAll register set of comma separated plugins in container
RegisterAll(service ...interface{}) error
RegisterAll(service ...any) error
// Init initializes all plugins (calling Init function), calculate vertices, invoke Collects and Provided functions if exist
Init() error
}

// Provider declares the ability to provide service edges of declared types.
Provider interface {
// Provides function return set of functions which provided dependencies to other plugins
Provides() []interface{}
Provides() []any
}

// Collector declares the ability to accept the plugins which match the provided method signature.
Collector interface {
// Collects search for the structures or (and) interfaces in the arguments and provides it for the plugin
Collects() []interface{}
Collects() []any
}
)
31 changes: 16 additions & 15 deletions pkg/container/endure.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type Endure struct {
stopTimeout time.Duration

// deps is a map with all saved deps
deps map[string]interface{}
deps map[string]any
depsOrd []string
// disabled is a map with disabled deps
disabled map[string]bool
Expand Down Expand Up @@ -95,16 +95,17 @@ type Options func(endure *Endure)
/*
NewContainer returns empty endure container
Input parameters: logLevel
-1 is the most informative level - DebugLevel --> also turns on pprof endpoint
0 - InfoLevel defines info log level.
1 -
2 - WarnLevel defines warn log level.
3 - ErrorLevel defines error log level.
4 - FatalLevel defines fatal log level.
5 - PanicLevel defines panic log level.
6 - NoLevel defines an absent log level.
7 - Disabled disables the logger.
see the endure.Level
-1 is the most informative level - DebugLevel --> also turns on pprof endpoint
0 - InfoLevel defines info log level.
1 -
2 - WarnLevel defines warn log level.
3 - ErrorLevel defines error log level.
4 - FatalLevel defines fatal log level.
5 - PanicLevel defines panic log level.
6 - NoLevel defines an absent log level.
7 - Disabled disables the logger.
see the endure.Level
*/
func NewContainer(logger *zap.Logger, options ...Options) (*Endure, error) {
const op = errors.Op("new_container")
Expand All @@ -120,7 +121,7 @@ func NewContainer(logger *zap.Logger, options ...Options) (*Endure, error) {
output: Empty,
disabled: make(map[string]bool),
initialized: make(map[string]bool),
deps: make(map[string]interface{}, 5),
deps: make(map[string]any, 5),
depsOrd: make([]string, 0, 2),
}

Expand Down Expand Up @@ -235,7 +236,7 @@ func profile() {
}

// Register registers the dependencies in the Endure graph without invoking any methods
func (e *Endure) Register(vertex interface{}) error {
func (e *Endure) Register(vertex any) error {
const op = errors.Op("endure_register")
t := reflect.TypeOf(vertex)
vertexID := removePointerAsterisk(t.String())
Expand Down Expand Up @@ -275,7 +276,7 @@ func (e *Endure) Register(vertex interface{}) error {
return nil
}

func (e *Endure) reRegister(vertex interface{}) error {
func (e *Endure) reRegister(vertex any) error {
const op = errors.Op("endure_register")
t := reflect.TypeOf(vertex)
vertexID := removePointerAsterisk(t.String())
Expand All @@ -293,7 +294,7 @@ func (e *Endure) reRegister(vertex interface{}) error {
}

// RegisterAll is the helper for the register to register more than one structure in the endure
func (e *Endure) RegisterAll(plugins ...interface{}) error {
func (e *Endure) RegisterAll(plugins ...any) error {
const op = errors.Op("endure_register_all")
for _, plugin := range plugins {
err := e.Register(plugin)
Expand Down
4 changes: 1 addition & 3 deletions pkg/container/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
)

/*
Traverse the DLL in the forward direction
Traverse the DLL in the forward direction
*/
func (e *Endure) internalInit(vrtx *vertex.Vertex) error {
const op = errors.Op("endure_internal_init")
Expand All @@ -37,7 +36,6 @@ func (e *Endure) internalInit(vrtx *vertex.Vertex) error {

/*
Here we also track the Disabled vertices. If the vertex is disabled we should re-calculate the tree
*/
func (e *Endure) callInitFn(init reflect.Method, vrtx *vertex.Vertex) error {
const op = errors.Op("endure_call_init_fn")
Expand Down
6 changes: 3 additions & 3 deletions pkg/container/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/roadrunner-server/errors"
)

func providersReturnType(m interface{}) ([]reflect.Type, error) {
func providersReturnType(m any) ([]reflect.Type, error) {
const op = errors.Op("endure_providers_return_type")
r := reflect.TypeOf(m)
if r.Kind() != reflect.Func {
Expand All @@ -29,7 +29,7 @@ func providersReturnType(m interface{}) ([]reflect.Type, error) {
return ret, nil
}

func fnIn(m interface{}) ([]reflect.Type, error) {
func fnIn(m any) ([]reflect.Type, error) {
const op = errors.Op("fn_in")
r := reflect.TypeOf(m)
if r.Kind() != reflect.Func {
Expand Down Expand Up @@ -58,7 +58,7 @@ func functionParameters(r reflect.Method) []reflect.Type {
return args
}

func getFunctionName(i interface{}) string {
func getFunctionName(i any) string {
rawName := runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
name := strings.TrimPrefix(filepath.Ext(rawName), ".")

Expand Down
2 changes: 1 addition & 1 deletion pkg/container/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/roadrunner-server/errors"
)

func (e *Endure) register(name string, vrtx interface{}) error {
func (e *Endure) register(name string, vrtx any) error {
// check the vertex
const op = errors.Op("endure_register")
if e.graph.HasVertex(name) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/fsm/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type FSM interface {
// InitialState sets the initial FSM state
InitialState(st State)
// Transition used to move from one state to another
Transition(event Event, args ...interface{}) (interface{}, error)
Transition(event Event, args ...any) (any, error)
}

// NewFSM returns new FSM implementation based on initial state and callbacks to move from one state to another
Expand Down Expand Up @@ -160,7 +160,7 @@ Event -> Start. Error on other events (Initialize, Stop)
Event -> Stop. Error on other events (Start, Initialize)
3. Stopping -> Stopped
*/
func (f *FSMImpl) Transition(event Event, args ...interface{}) (interface{}, error) {
func (f *FSMImpl) Transition(event Event, args ...any) (any, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
err := f.recognizer(event)
Expand Down
2 changes: 1 addition & 1 deletion pkg/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (g *Graph) depthFirstSearch(deps []*vertex.Vertex, tmp map[string]*vertex.V
}

// AddVertex adds an vertex to the graph with its ID, value and meta information
func (g *Graph) AddVertex(vertexID string, vertexIface interface{}) {
func (g *Graph) AddVertex(vertexID string, vertexIface any) {
v := vertex.NewVertex()
v.ID = vertexID
v.Iface = vertexIface
Expand Down
2 changes: 1 addition & 1 deletion pkg/vertex/vertex.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type Vertex struct {
// ID of the vertex, currently string representation of the structure fn
ID string
// Vertex (Registered structure)
Iface interface{}
Iface any
// Meta information about current Vertex
Meta Meta
// Dependencies of the node
Expand Down
4 changes: 2 additions & 2 deletions tests/happy_scenarios/plugin1/plugin1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
type S1 struct {
}

func (s1 *S1) Collects() []interface{} {
return []interface{}{
func (s1 *S1) Collects() []any {
return []any{
s1.AddService,
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/happy_scenarios/plugin2/plugin2.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func (s2 *S2) Init(db *plugin4.DB) error {
return nil
}

func (s2 *S2) Provides() []interface{} {
return []interface{}{s2.CreateDB}
func (s2 *S2) Provides() []any {
return []any{s2.CreateDB}
}

func (s2 *S2) CreateDB() (*DB, error) {
Expand Down
4 changes: 2 additions & 2 deletions tests/happy_scenarios/plugin3/plugin3.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
type S3 struct {
}

func (s3 *S3) Collects() []interface{} {
return []interface{}{
func (s3 *S3) Collects() []any {
return []any{
s3.SomeOtherDep,
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/happy_scenarios/plugin4/plugin4.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func (s *S4) Init(foo5 *plugin5.S5, fooWriter plugin6.FooWriter) error {
}

// But provide some
func (s *S4) Provides() []interface{} {
return []interface{}{
func (s *S4) Provides() []any {
return []any{
s.CreateAnotherDB,
}
}
Expand All @@ -33,8 +33,8 @@ func (s *S4) CreateAnotherDB() (*DB, error) {
}, nil
}

func (s *S4) Collects() []interface{} {
return []interface{}{
func (s *S4) Collects() []any {
return []any{
s.AddService,
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/happy_scenarios/plugin6/plugin6.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func (s *S6Interface) Stop() error {
return nil
}

func (s *S6Interface) Provides() []interface{} {
return []interface{}{s.ProvideInterface}
func (s *S6Interface) Provides() []any {
return []any{s.ProvideInterface}
}

func (s *S6Interface) ProvideInterface() FooWriter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func (s *Plugin2) Init() error {
}

// But provide some
func (s *Plugin2) Provides() []interface{} {
return []interface{}{
func (s *Plugin2) Provides() []any {
return []any{
s.CreateAnotherDB,
}
}
Expand Down
Loading

0 comments on commit fcd3f6d

Please sign in to comment.