Skip to content

Commit f7c96c9

Browse files
committed
* No need to have exported types and functions in common.go
* Simplify functions and remove `PercentCodec` type
1 parent b62e0aa commit f7c96c9

File tree

2 files changed

+29
-38
lines changed

2 files changed

+29
-38
lines changed

rabbitmq_amqp/amqp_queue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (a *AmqpQueue) Declare(ctx context.Context) (IQueueInfo, error) {
142142
}
143143

144144
if a.name == "" {
145-
a.name = GenerateNameWithDefaultPrefix()
145+
a.name = generateNameWithDefaultPrefix()
146146
}
147147

148148
path := queuePath(a.name)

rabbitmq_amqp/common.go

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,26 @@ import (
99
"strings"
1010
)
1111

12-
type PercentCodec struct{}
12+
const (
13+
responseCode200 = 200
14+
responseCode201 = 201
15+
responseCode204 = 204
16+
responseCode409 = 409
17+
commandPut = "PUT"
18+
commandGet = "GET"
19+
commandPost = "POST"
20+
commandDelete = "DELETE"
21+
commandReplyTo = "$me"
22+
managementNodeAddress = "/management"
23+
linkPairName = "management-link-pair"
24+
exchanges = "exchanges"
25+
key = "key"
26+
queues = "queues"
27+
bindings = "bindings"
28+
)
1329

14-
// Encode takes a string and returns its percent-encoded representation.
15-
func (pc *PercentCodec) Encode(input string) string {
30+
// encodePathSegments takes a string and returns its percent-encoded representation.
31+
func encodePathSegments(input string) string {
1632
var encoded strings.Builder
1733

1834
// Iterate over each character in the input string
@@ -30,7 +46,7 @@ func (pc *PercentCodec) Encode(input string) string {
3046
}
3147

3248
// Decode takes a percent-encoded string and returns its decoded representation.
33-
func (pc *PercentCodec) Decode(input string) (string, error) {
49+
func decode(input string) (string, error) {
3450
// Use url.QueryUnescape which properly decodes percent-encoded strings
3551
decoded, err := url.QueryUnescape(input)
3652
if err != nil {
@@ -40,27 +56,6 @@ func (pc *PercentCodec) Decode(input string) (string, error) {
4056
return decoded, nil
4157
}
4258

43-
const (
44-
responseCode200 = 200
45-
responseCode201 = 201
46-
responseCode204 = 204
47-
responseCode409 = 409
48-
commandPut = "PUT"
49-
commandGet = "GET"
50-
commandPost = "POST"
51-
commandDelete = "DELETE"
52-
commandReplyTo = "$me"
53-
managementNodeAddress = "/management"
54-
linkPairName = "management-link-pair"
55-
)
56-
57-
const (
58-
Exchanges = "exchanges"
59-
Key = "key"
60-
Queues = "queues"
61-
Bindings = "bindings"
62-
)
63-
6459
// isUnreserved checks if a character is an unreserved character in percent encoding
6560
// Unreserved characters are: A-Z, a-z, 0-9, -, ., _, ~
6661
func isUnreserved(char rune) bool {
@@ -70,20 +65,16 @@ func isUnreserved(char rune) bool {
7065
char == '-' || char == '.' || char == '_' || char == '~'
7166
}
7267

73-
func encodePathSegments(pathSegments string) string {
74-
return (&PercentCodec{}).Encode(pathSegments)
75-
}
76-
7768
func queuePath(queueName string) string {
78-
return "/" + Queues + "/" + encodePathSegments(queueName)
69+
return "/" + queues + "/" + encodePathSegments(queueName)
7970
}
8071

8172
func exchangePath(exchangeName string) string {
82-
return "/" + Exchanges + "/" + encodePathSegments(exchangeName)
73+
return "/" + exchanges + "/" + encodePathSegments(exchangeName)
8374
}
8475

8576
func bindingPath() string {
86-
return "/" + Bindings
77+
return "/" + bindings
8778
}
8879

8980
func bindingPathWithExchangeQueueKey(toQueue bool, sourceName, destinationName, key string) string {
@@ -95,7 +86,7 @@ func bindingPathWithExchangeQueueKey(toQueue bool, sourceName, destinationName,
9586
destinationType = "dstq"
9687
}
9788
format := "/%s/src=%s;%s=%s;key=%s;args="
98-
return fmt.Sprintf(format, Bindings, sourceNameEncoded, destinationType, destinationNameEncoded, keyEncoded)
89+
return fmt.Sprintf(format, bindings, sourceNameEncoded, destinationType, destinationNameEncoded, keyEncoded)
9990

10091
}
10192

@@ -106,12 +97,12 @@ func validatePositive(label string, value int64) error {
10697
return nil
10798
}
10899

109-
func GenerateNameWithDefaultPrefix() string {
110-
return GenerateName("client.gen-")
100+
func generateNameWithDefaultPrefix() string {
101+
return generateName("client.gen-")
111102
}
112103

113-
// GenerateName generates a unique name with the given prefix
114-
func GenerateName(prefix string) string {
104+
// generateName generates a unique name with the given prefix
105+
func generateName(prefix string) string {
115106
uid := uuid.New()
116107
uuidBytes := []byte(uid.String())
117108
md5obj := md5.New()

0 commit comments

Comments
 (0)