-
Notifications
You must be signed in to change notification settings - Fork 51
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 #240 from trheyi/main
Refactor error handling
- Loading branch information
Showing
10 changed files
with
166 additions
and
21 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
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,78 @@ | ||
package moapi | ||
|
||
import ( | ||
"github.com/yaoapp/gou/application" | ||
"github.com/yaoapp/gou/helper" | ||
"github.com/yaoapp/xun/dbal/query" | ||
"github.com/yaoapp/xun/dbal/schema" | ||
) | ||
|
||
// Connector connector | ||
type Connector struct { | ||
id string | ||
file string | ||
Name string `json:"name"` | ||
Options Options `json:"options"` | ||
} | ||
|
||
// Options the redis connector option | ||
type Options struct { | ||
Proxy string `json:"proxy,omitempty"` | ||
Model string `json:"model,omitempty"` | ||
Key string `json:"key"` | ||
} | ||
|
||
// Register the connections from dsl | ||
func (o *Connector) Register(file string, id string, dsl []byte) error { | ||
o.id = id | ||
o.file = file | ||
err := application.Parse(file, dsl, o) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
o.Options.Proxy = helper.EnvString(o.Options.Proxy) | ||
o.Options.Model = helper.EnvString(o.Options.Model) | ||
o.Options.Key = helper.EnvString(o.Options.Key) | ||
return nil | ||
} | ||
|
||
// Is the connections from dsl | ||
func (o *Connector) Is(typ int) bool { | ||
return 6 == typ || 8 == typ | ||
} | ||
|
||
// ID get connector id | ||
func (o *Connector) ID() string { | ||
return o.id | ||
} | ||
|
||
// Query get connector query interface | ||
func (o *Connector) Query() (query.Query, error) { | ||
return nil, nil | ||
} | ||
|
||
// Schema get connector schema interface | ||
func (o *Connector) Schema() (schema.Schema, error) { | ||
return nil, nil | ||
} | ||
|
||
// Close connections | ||
func (o *Connector) Close() error { | ||
return nil | ||
} | ||
|
||
// Setting get the connection setting | ||
func (o *Connector) Setting() map[string]interface{} { | ||
|
||
host := "https://api.moapi.ai" | ||
if o.Options.Proxy != "" { | ||
host = o.Options.Proxy | ||
} | ||
|
||
return map[string]interface{}{ | ||
"host": host, | ||
"key": o.Options.Key, | ||
"model": o.Options.Model, | ||
} | ||
} |
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