mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-20 16:14:29 +01:00
gofmt code in utils subdirectory
* formatted code by running 'gofmt'
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SignalCliTrustMode int
|
type SignalCliTrustMode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
OnFirstUseTrust SignalCliTrustMode = iota
|
OnFirstUseTrust SignalCliTrustMode = iota
|
||||||
AlwaysTrust
|
AlwaysTrust
|
||||||
NeverTrust
|
NeverTrust
|
||||||
)
|
)
|
||||||
|
|
||||||
func TrustModeToString(trustMode SignalCliTrustMode) (string, error) {
|
func TrustModeToString(trustMode SignalCliTrustMode) (string, error) {
|
||||||
@@ -38,7 +38,7 @@ func StringToTrustMode(trustMode string) (SignalCliTrustMode, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SignalCliApiConfigEntry struct {
|
type SignalCliApiConfigEntry struct {
|
||||||
TrustMode SignalCliTrustMode `yaml:"trust_mode"`
|
TrustMode SignalCliTrustMode `yaml:"trust_mode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SignalCliApiConfigEntries struct {
|
type SignalCliApiConfigEntries struct {
|
||||||
@@ -47,7 +47,7 @@ type SignalCliApiConfigEntries struct {
|
|||||||
|
|
||||||
type SignalCliApiConfig struct {
|
type SignalCliApiConfig struct {
|
||||||
config SignalCliApiConfigEntries
|
config SignalCliApiConfigEntries
|
||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSignalCliApiConfig() *SignalCliApiConfig {
|
func NewSignalCliApiConfig() *SignalCliApiConfig {
|
||||||
|
|||||||
@@ -5,29 +5,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Normal string = "NORMAL"
|
Normal string = "NORMAL"
|
||||||
Bold = "BOLD"
|
Bold = "BOLD"
|
||||||
Italic = "ITALIC"
|
Italic = "ITALIC"
|
||||||
Monospace = "MONOSPACE"
|
Monospace = "MONOSPACE"
|
||||||
Strikethrough = "STRIKETHROUGH"
|
Strikethrough = "STRIKETHROUGH"
|
||||||
Spoiler = "SPOILER"
|
Spoiler = "SPOILER"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
None int = 0
|
None int = 0
|
||||||
ItalicBegin = 1
|
ItalicBegin = 1
|
||||||
ItalicEnd = 2
|
ItalicEnd = 2
|
||||||
BoldBegin = 3
|
BoldBegin = 3
|
||||||
BoldEnd1 = 4
|
BoldEnd1 = 4
|
||||||
BoldEnd2 = 5
|
BoldEnd2 = 5
|
||||||
MonoSpaceBegin = 6
|
MonoSpaceBegin = 6
|
||||||
MonoSpaceEnd = 7
|
MonoSpaceEnd = 7
|
||||||
StrikethroughBegin = 8
|
StrikethroughBegin = 8
|
||||||
StrikethroughEnd = 9
|
StrikethroughEnd = 9
|
||||||
SpoilerBegin1 = 10
|
SpoilerBegin1 = 10
|
||||||
SpoilerBegin = 11
|
SpoilerBegin = 11
|
||||||
SpoilerEnd1 = 12
|
SpoilerEnd1 = 12
|
||||||
SpoilerEnd2 = 13
|
SpoilerEnd2 = 13
|
||||||
)
|
)
|
||||||
|
|
||||||
func getUtf16CharacterCount(s string) int {
|
func getUtf16CharacterCount(s string) int {
|
||||||
@@ -35,7 +35,7 @@ func getUtf16CharacterCount(s string) int {
|
|||||||
if stringLength == 1 {
|
if stringLength == 1 {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
return stringLength/2
|
return stringLength / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAdditionalCharacterCount(characterCount int) int {
|
func getAdditionalCharacterCount(characterCount int) int {
|
||||||
@@ -123,7 +123,7 @@ func ParseMarkdownMessage(message string) (string, []string) {
|
|||||||
lastChar = string(v)
|
lastChar = string(v)
|
||||||
|
|
||||||
if state == ItalicEnd || state == BoldEnd2 || state == MonoSpaceEnd || state == StrikethroughEnd || state == SpoilerEnd2 {
|
if state == ItalicEnd || state == BoldEnd2 || state == MonoSpaceEnd || state == StrikethroughEnd || state == SpoilerEnd2 {
|
||||||
signalCliFormatStrings = append(signalCliFormatStrings, strconv.Itoa(textFormatBegin)+":"+strconv.Itoa(textFormatLength + additionalCharacterCount)+":"+textFormat)
|
signalCliFormatStrings = append(signalCliFormatStrings, strconv.Itoa(textFormatBegin)+":"+strconv.Itoa(textFormatLength+additionalCharacterCount)+":"+textFormat)
|
||||||
state = None
|
state = None
|
||||||
textFormatBegin = 0
|
textFormatBegin = 0
|
||||||
textFormatLength = 0
|
textFormatLength = 0
|
||||||
|
|||||||
@@ -16,19 +16,19 @@ func expectFormatStringsEqual(t *testing.T, formatStrings1 []string, formatStrin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSimpleMessage1(t *testing.T) {
|
func TestSimpleMessage1(t *testing.T) {
|
||||||
message, signalCliFormatStrings := ParseMarkdownMessage("*italic*")
|
message, signalCliFormatStrings := ParseMarkdownMessage("*italic*")
|
||||||
expectMessageEqual(t, message, "italic")
|
expectMessageEqual(t, message, "italic")
|
||||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"0:6:ITALIC"})
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"0:6:ITALIC"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSimpleMessage(t *testing.T) {
|
func TestSimpleMessage(t *testing.T) {
|
||||||
message, signalCliFormatStrings := ParseMarkdownMessage("*This is a italic message*")
|
message, signalCliFormatStrings := ParseMarkdownMessage("*This is a italic message*")
|
||||||
expectMessageEqual(t, message, "This is a italic message")
|
expectMessageEqual(t, message, "This is a italic message")
|
||||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"0:24:ITALIC"})
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"0:24:ITALIC"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoldAndItalicMessage(t *testing.T) {
|
func TestBoldAndItalicMessage(t *testing.T) {
|
||||||
message, signalCliFormatStrings := ParseMarkdownMessage("This is a **bold** and *italic* message")
|
message, signalCliFormatStrings := ParseMarkdownMessage("This is a **bold** and *italic* message")
|
||||||
expectMessageEqual(t, message, "This is a bold and italic message")
|
expectMessageEqual(t, message, "This is a bold and italic message")
|
||||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"10:4:BOLD", "19:6:ITALIC"})
|
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"10:4:BOLD", "19:6:ITALIC"})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user