mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
The server module named github.com/hanzoai/team/server/v8 — a path that resolves to the retired workspace's repository, not this one — while server/public still published github.com/mattermost/mattermost/server/public. Both are github.com/hanzoteam/server/... now, which is where this code actually lives. That second half is what made the binary unbootable. Upstream's public path stayed claimed by upstream, mattermost-plugin-ai imported it, and the build linked public/model twice; public/plugin's gob.Register then ran twice under one name and panicked at init, before main. Reverting the rename traded the brand for a working binary. Rebranding the plugin alongside it needs no such trade: the agents fork is github.com/hanzoteam/agents/v2 against our public module, so no module named mattermost/mattermost is in the graph at all. Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and it is ours.
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
// package driver implements a DB driver that can be used by plugins
|
|
// to make SQL queries using RPC. This helps to avoid opening new connections
|
|
// for every plugin, and lets everyone use the central connection
|
|
// pool in the server.
|
|
// The tests for this package are at app/plugin_api_tests/test_db_driver/main.go.
|
|
package driver
|
|
|
|
import (
|
|
"context"
|
|
"database/sql/driver"
|
|
|
|
"github.com/hanzoteam/server/server/public/plugin"
|
|
)
|
|
|
|
var (
|
|
// Compile-time check to ensure Connector implements the interface.
|
|
_ driver.Connector = &Connector{}
|
|
)
|
|
|
|
// Connector is the DB connector which is used to
|
|
// communicate with the DB API.
|
|
type Connector struct {
|
|
api plugin.Driver
|
|
isMaster bool
|
|
}
|
|
|
|
// NewConnector returns a DB connector that can be used to return a sql.DB object.
|
|
// It takes a plugin.Driver implementation and a boolean flag to indicate whether
|
|
// to connect to a master or replica DB instance.
|
|
func NewConnector(api plugin.Driver, isMaster bool) *Connector {
|
|
return &Connector{api: api, isMaster: isMaster}
|
|
}
|
|
|
|
func (c *Connector) Connect(_ context.Context) (driver.Conn, error) {
|
|
connID, err := c.api.Conn(c.isMaster)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Conn{id: connID, api: c.api}, nil
|
|
}
|
|
|
|
func (c *Connector) Driver() driver.Driver {
|
|
return &Driver{c: c}
|
|
}
|
|
|
|
// Driver is a DB driver implementation.
|
|
type Driver struct {
|
|
c *Connector
|
|
}
|
|
|
|
func (d Driver) Open(name string) (driver.Conn, error) {
|
|
return d.c.Connect(context.Background())
|
|
}
|