database: add NewNetwork
This commit is contained in:
parent
bb8397057e
commit
e19dd8f0da
@ -175,7 +175,8 @@ func main() {
|
||||
if ok {
|
||||
logger.Printf("updating existing network")
|
||||
} else {
|
||||
n = &database.Network{Name: netName}
|
||||
n = database.NewNetwork("")
|
||||
n.Name = netName
|
||||
logger.Printf("creating new network")
|
||||
}
|
||||
|
||||
|
@ -161,6 +161,13 @@ type Network struct {
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
func NewNetwork(addr string) *Network {
|
||||
return &Network{
|
||||
Addr: addr,
|
||||
Enabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (net *Network) GetName() string {
|
||||
if net.Name != "" {
|
||||
return net.Name
|
||||
|
@ -1403,13 +1403,12 @@ func (dc *downstreamConn) loadNetwork(ctx context.Context) error {
|
||||
}}
|
||||
}
|
||||
|
||||
record := database.NewNetwork(dc.registration.networkName)
|
||||
record.Nick = nick
|
||||
|
||||
dc.logger.Printf("auto-saving network %q", dc.registration.networkName)
|
||||
var err error
|
||||
network, err = dc.user.createNetwork(ctx, &database.Network{
|
||||
Addr: dc.registration.networkName,
|
||||
Nick: nick,
|
||||
Enabled: true,
|
||||
})
|
||||
network, err = dc.user.createNetwork(ctx, record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -3069,7 +3068,8 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
|
||||
}
|
||||
attrs := irc.ParseTags(attrsStr)
|
||||
|
||||
record := &database.Network{Nick: dc.nick, Enabled: true}
|
||||
record := database.NewNetwork("")
|
||||
record.Nick = dc.nick
|
||||
if err := updateNetworkAttrs(record, attrs, subcommand); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -74,12 +74,8 @@ func createTestUpstream(t *testing.T, db database.Database, user *database.User)
|
||||
t.Fatalf("failed to create TCP listener: %v", err)
|
||||
}
|
||||
|
||||
network := &database.Network{
|
||||
Name: "testnet",
|
||||
Addr: "irc+insecure://" + ln.Addr().String(),
|
||||
Nick: user.Username,
|
||||
Enabled: true,
|
||||
}
|
||||
network := database.NewNetwork("irc+insecure://" + ln.Addr().String())
|
||||
network.Name = "testnet"
|
||||
if err := db.StoreNetwork(context.Background(), user.ID, network); err != nil {
|
||||
t.Fatalf("failed to store test network: %v", err)
|
||||
}
|
||||
|
@ -577,10 +577,7 @@ func handleServiceNetworkCreate(ctx *serviceContext, params []string) error {
|
||||
return fmt.Errorf("flag -addr is required")
|
||||
}
|
||||
|
||||
record := &database.Network{
|
||||
Addr: *fs.Addr,
|
||||
Enabled: true,
|
||||
}
|
||||
record := database.NewNetwork(*fs.Addr)
|
||||
if err := fs.update(record); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user