github.com/vmware/transport-go@v1.3.4/stompserver/config.go (about) 1 // Copyright 2019-2020 VMware, Inc. 2 // SPDX-License-Identifier: BSD-2-Clause 3 4 package stompserver 5 6 import "strings" 7 8 type StompConfig interface { 9 HeartBeat() int64 10 AppDestinationPrefix() []string 11 IsAppRequestDestination(destination string) bool 12 } 13 14 type stompConfig struct { 15 heartbeat int64 16 appDestPrefix []string 17 } 18 19 func NewStompConfig(heartBeatMs int64, appDestinationPrefix []string) StompConfig { 20 prefixes := make([]string, len(appDestinationPrefix)) 21 for i := 0; i < len(appDestinationPrefix); i++ { 22 if appDestinationPrefix[i] != "" && !strings.HasSuffix(appDestinationPrefix[i], "/") { 23 prefixes[i] = appDestinationPrefix[i] + "/" 24 } else { 25 prefixes[i] = appDestinationPrefix[i] 26 } 27 } 28 29 return &stompConfig{ 30 heartbeat: heartBeatMs, 31 appDestPrefix: prefixes, 32 } 33 } 34 35 func (c *stompConfig) HeartBeat() int64 { 36 return c.heartbeat 37 } 38 39 func (c *stompConfig) AppDestinationPrefix() []string { 40 return c.appDestPrefix 41 } 42 43 func (c *stompConfig) IsAppRequestDestination(destination string) bool { 44 for _, prefix := range c.appDestPrefix { 45 if prefix != "" && strings.HasPrefix(destination, prefix) { 46 return true 47 } 48 } 49 return false 50 }