code: func (l *AdvisoryLock) Lock() error {
  	l.mu.Lock()
  	defer l.mu.Unlock()
  
  	if l.commited {
  		panic("lock called on commited lock")
  	}
  
  	if l.LockTimeout != 0 {
  		_, err := l.tx.Exec(fmt.Sprintf("SET LOCAL lock_timeout = %d", int(l.LockTimeout.Seconds()*1000)))
  		if err != nil {
  			return fmt.Errorf("error setting lock timeout: %v", err)
  		}
  	}
  
  	_, err := l.tx.Exec(fmt.Sprintf("SELECT pg_advisory_lock($1) /* %s */", l.Context), l.key)
  	if err != nil {
  		// If there's an error trying to obtain the lock, probably the
  		// safest thing to do is commit the transaction and make this
  		// lock invalid.
  		l.commit()
  
  		if err, ok := err.(*pq.Error); ok {
  			switch err.Code.Name() {
  			case "query_canceled":
  				return Canceled
  			case "lock_not_available":
  				return ErrLockTimeout
  			}
  		}
  
  		return fmt.Errorf("error obtaining lock: %v", err)
  	}
  
  	l.c += 1
  
  	return nil
  }
docs: // Lock obtains the advisory lock.