Changeset 500 in code for trunk/user.go


Ignore:
Timestamp:
Apr 13, 2021, 5:33:06 PM (4 years ago)
Author:
contact
Message:

Error out on network name conflict

Closes: https://todo.sr.ht/~emersion/soju/29

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user.go

    r499 r500  
    672672}
    673673
     674func (u *user) checkNetwork(record *Network) error {
     675        for _, net := range u.networks {
     676                if net.GetName() == record.GetName() && net.ID != record.ID {
     677                        return fmt.Errorf("a network with the name %q already exists", record.GetName())
     678                }
     679        }
     680        return nil
     681}
     682
    674683func (u *user) createNetwork(record *Network) (*network, error) {
    675684        if record.ID != 0 {
    676685                panic("tried creating an already-existing network")
     686        }
     687
     688        if err := u.checkNetwork(record); err != nil {
     689                return nil, err
    677690        }
    678691
     
    691704        if record.ID == 0 {
    692705                panic("tried updating a new network")
     706        }
     707
     708        if err := u.checkNetwork(record); err != nil {
     709                return nil, err
    693710        }
    694711
Note: See TracChangeset for help on using the changeset viewer.