Skip to content

Commit

Permalink
Refactor New function in connector package to enhance connector regis…
Browse files Browse the repository at this point in the history
…tration. The function now constructs a file name using the connector ID, replacing dots with slashes, and registers the connector with the new file name. This change improves organization and clarity in connector management.
  • Loading branch information
trheyi committed Dec 14, 2024
1 parent 8dec253 commit 852a51c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package connector

import (
"fmt"
"strings"

"github.com/yaoapp/gou/application"
"github.com/yaoapp/gou/connector/database"
Expand Down Expand Up @@ -43,12 +44,18 @@ func Load(file string, id string) (Connector, error) {
}

// New create a new connector
func New(typ string, id string, data []byte) (Connector, error) {
func New(typ string, id string, dsl []byte) (Connector, error) {
c, err := make(typ)
if err != nil {
return nil, err
}
c.Register(id, "__source__", data)

file := "__source__" + strings.Replace(id, ".", "/", -1) + ".conn.yao"
err = c.Register(file, id, dsl)
if err != nil {
return nil, err
}

Connectors[id] = c
return Connectors[id], nil
}
Expand Down

0 comments on commit 852a51c

Please sign in to comment.