MCPcopy Create free account
hub / github.com/pydio/cells / Open

Method Open

common/config/sql/sql.go:60–127  ·  view source on GitHub ↗
(ctx context.Context, urlstr string, base config.Store)

Source from the content-addressed store, hash-verified

58}
59
60func (o *URLOpener) Open(ctx context.Context, urlstr string, base config.Store) (config.Store, error) {
61 u, err := url.Parse(urlstr)
62 if err != nil {
63 return nil, err
64 }
65
66 var opts []kv.Option
67
68 encode := u.Query().Get("encode")
69 switch encode {
70 case "string":
71 opts = append(opts, kv.WithString())
72 case "yaml":
73 opts = append(opts, kv.WithYAML())
74 case "json":
75 opts = append(opts, kv.WithJSON())
76 default:
77 opts = append(opts, kv.WithJSON())
78 }
79
80 if data := u.Query().Get("data"); data != "" {
81 //unescapedData, err := url.QueryUnescape(data)
82 //if err != nil {
83 // return nil, err
84 //}
85 opts = append(opts, kv.WithInitData([]byte(data)))
86 }
87
88 driver := u.Scheme
89 dsn := u.Host
90 prefix := u.Query().Get("prefix")
91
92 switch u.Scheme {
93 case "mysql":
94 driver, dsn, prefix = openurl.URLToDSN(u)
95 }
96
97 store, err := New(ctx, driver, dsn, prefix)
98 if err != nil {
99 fmt.Println("And the error is ? ", err)
100 }
101
102 envPrefix := u.Query().Get("env")
103 if envPrefix != "" {
104 env := os.Environ()
105 for _, v := range env {
106 if strings.HasPrefix(v, envPrefix) {
107 vv := strings.SplitN(v, "=", 2)
108 if len(vv) == 2 {
109 k := strings.TrimPrefix(vv[0], envPrefix)
110 k = strings.ReplaceAll(k, "_", "/")
111 k = strings.ToLower(k)
112
113 var m map[string]interface{}
114 msg, err := strconv.Unquote(vv[1])
115 if err != nil {
116 msg = vv[1]
117 }

Callers

nothing calls this directly

Calls 12

WithStringFunction · 0.92
WithYAMLFunction · 0.92
WithJSONFunction · 0.92
WithInitDataFunction · 0.92
URLToDSNFunction · 0.92
PrintlnMethod · 0.80
NewFunction · 0.70
ParseMethod · 0.65
GetMethod · 0.65
UnmarshalMethod · 0.65
SetMethod · 0.65
ValMethod · 0.65

Tested by

no test coverage detected