2 // Copyright © 2014-2019 Guy M. Allard
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 Helper package for stompngo users.
20 Extract commonly used data elements from the environment, and expose
34 host
= "localhost" // default host
35 port
= "61613" // default port
36 protocol
= "1.2" // Default protocol level
37 login
= "guest" // default login
38 passcode
= "guest" // default passcode
39 vhost
= "localhost" // default vhost
40 heartbeats
= "0,0" // default (no) heartbeats
41 dest
= "/queue/sng.sample.stomp.destination" // default destination
42 scc
= 1 // Subchannel capacity
43 nmsgs
= 1 // default number of messages (useful at times)
44 maxbl
= -1 // Max body length to dump (-1 => no limit)
45 vhLock sync
.Mutex
// vhsost set lock
46 nmLock sync
.Mutex
// nmsgs set lock
52 de
:= os
.Getenv("STOMP_DEST")
59 // Heartbeats returns client requested heart beat values.
60 func Heartbeats() string {
62 hb
:= os
.Getenv("STOMP_HEARTBEATS")
69 // Host returns a default connection hostname.
72 he
:= os
.Getenv("STOMP_HOST")
79 // HostAndPort returns a default host and port (useful for Dial).
80 func HostAndPort() (string, string) {
84 // Login returns a default login ID.
87 l
:= os
.Getenv("STOMP_LOGIN")
101 defer nmLock
.Unlock()
102 ns
:= os
.Getenv("STOMP_NMSGS")
106 n
, e
:= strconv
.ParseInt(ns
, 10, 0)
108 log
.Printf("NMSGS Conversion error: %v\n", e
)
115 // Passcode returns a default passcode.
116 func Passcode() string {
118 pc
:= os
.Getenv("STOMP_PASSCODE")
128 // True if persistent messages are desired.
129 func Persistent() bool {
130 f
:= os
.Getenv("STOMP_PERSISTENT")
137 // Port returns a default connection port.
140 pt
:= os
.Getenv("STOMP_PORT")
147 // Protocol returns a default level.
148 func Protocol() string {
150 pr
:= os
.Getenv("STOMP_PROTOCOL")
157 func SubChanCap() int {
158 if s
:= os
.Getenv("STOMP_SUBCHANCAP"); s
!= "" {
159 i
, e
:= strconv
.ParseInt(s
, 10, 32)
161 log
.Println("SUBCHANCAP conversion error", e
)
169 // Vhost returns a default vhost name.
170 func Vhost() string {
173 defer vhLock
.Unlock()
174 vh
:= os
.Getenv("STOMP_VHOST")
183 func MaxBodyLength() int {
184 if s
:= os
.Getenv("STOMP_MAXBODYLENGTH"); s
!= "" {
185 i
, e
:= strconv
.ParseInt(s
, 10, 32)
187 log
.Println("MAXBODYLENGTH conversion error", e
)
195 // Optional set logger during connection start
196 func WantLogger() string {
197 return os
.Getenv("STOMP_LOGGER")