For example, what ChatGPT gave me:
func (q *Queue) Enqueue(b []byte) error { if len(b) > maxBodySize { return fmt.Errorf("payload too large") } q.mu.Lock() defer q.mu.Unlock() if len(q.data) >= q.maxMsg || q.bytes+len(b) > q.maxB { return errors.New("queue full") } cp := append([]byte(nil), b...) q.data = append(q.data, cp) q.bytes += len(cp) atomic.AddUint64(&q.enqueueCnt, 1) return nil }
func (q *queue) enqueue(b []byte) error { if len(b) > maxBody { return errors.New("payload too large") } q.mu.Lock() defer q.mu.Unlock() if len(q.data) >= maxMsgs || q.bytes+int64(len(b)) > maxBytes { return errors.New("queue full") } cp := append([]byte(nil), b...) q.data = append(q.data, cp) q.bytes += int64(len(cp)) atomic.AddUint64(&enqueueCnt, 1) return nil }
For example, what ChatGPT gave me:
The project: