15 Apr 2021
·
2 min read
·Article 11 / 119
GoHow to implement queue (queue) in Go Language
IH
Ihsan Arif
Writer at Santekno · Backend Engineer
Basic Definition
Queue or often we know is a queue data structure where the data we enter will be delivered, in other words the first data will come out first. Usually we often know that Istra FIFO (First in First Out).
According to information that Santekno can, Queue or queue is a collection of data whose additional elements can only be done at one end (called on the back side or rear), and delete or take elements done through another end (called the front or front side).
Queue Implementation
1package main
2
3type Queue struct {
4 items []int
5}
6
7func (q *Queue) Enqueue(i int) {
8 q.items = append(q.items, i)
9}
10
11func (q *Queue) Dequeue() int {
12 if len(q.items) == 0 {
13 return -1
14 }
15 item, items := q.items[0], q.items[1:]
16 q.items = items
17 return item
18}
19
20func main() {
21 q := Queue{}
22 q.Enqueue(1)
23 q.Enqueue(2)
24 q.Enqueue(3)
25
26 println(q.Dequeue())
27 println(q.Dequeue())
28 println(q.Dequeue())
29}Queue Implementation with Channel
1package main
2
3type Queue struct {
4 items chan int
5}
6
7func (q *Queue) Enqueue(i int) {
8 q.items <- i
9}
10
11func (q *Queue) Dequeue() int {
12 return <-q.items
13}
14
15func main() {
16 q := Queue{
17 items: make(chan int, 16),
18 }
19 q.Enqueue(1)
20 q.Enqueue(2)
21 q.Enqueue(3)
22
23 println(q.Dequeue())
24 println(q.Dequeue())
25 println(q.Dequeue())
26}Explanation
If you have seen how to implement the queue, the core of the data structure there are 2 enqueue operations, namely entering data into the rear elements (rear) and dequeue which is to retrieve data in the front side elements (front).
Related Articles
Go
20 Aug 2026
speckit.clarify: Structured Q&A to Clarify Golang Spec Details
12 mnt
Read
Go
19 Aug 2026
speckit.specify: Write Requirements Without Naming the Tech Stack
11 mnt
Read
Go
18 Aug 2026
speckit.constitution: The Project Constitution You Must Not Violate
12 mnt
Read
Go
17 Aug 2026
Spec Kit + Claude Code Integration: End-to-End Golang Project Setup
12 mnt
Read