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,23 +1,23 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"gopkg.in/yaml.v2"
|
||||
"errors"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
type SignalCliTrustMode int
|
||||
|
||||
const (
|
||||
OnFirstUseTrust SignalCliTrustMode = iota
|
||||
AlwaysTrust
|
||||
NeverTrust
|
||||
OnFirstUseTrust SignalCliTrustMode = iota
|
||||
AlwaysTrust
|
||||
NeverTrust
|
||||
)
|
||||
|
||||
func TrustModeToString(trustMode SignalCliTrustMode) (string, error) {
|
||||
if trustMode == OnFirstUseTrust {
|
||||
return "on-first-use", nil
|
||||
return "on-first-use", nil
|
||||
} else if trustMode == AlwaysTrust {
|
||||
return "always", nil
|
||||
} else if trustMode == NeverTrust {
|
||||
@@ -28,7 +28,7 @@ func TrustModeToString(trustMode SignalCliTrustMode) (string, error) {
|
||||
|
||||
func StringToTrustMode(trustMode string) (SignalCliTrustMode, error) {
|
||||
if trustMode == "on-first-use" {
|
||||
return OnFirstUseTrust, nil
|
||||
return OnFirstUseTrust, nil
|
||||
} else if trustMode == "always" {
|
||||
return AlwaysTrust, nil
|
||||
} else if trustMode == "never" {
|
||||
@@ -38,7 +38,7 @@ func StringToTrustMode(trustMode string) (SignalCliTrustMode, error) {
|
||||
}
|
||||
|
||||
type SignalCliApiConfigEntry struct {
|
||||
TrustMode SignalCliTrustMode `yaml:"trust_mode"`
|
||||
TrustMode SignalCliTrustMode `yaml:"trust_mode"`
|
||||
}
|
||||
|
||||
type SignalCliApiConfigEntries struct {
|
||||
@@ -47,7 +47,7 @@ type SignalCliApiConfigEntries struct {
|
||||
|
||||
type SignalCliApiConfig struct {
|
||||
config SignalCliApiConfigEntries
|
||||
path string
|
||||
path string
|
||||
}
|
||||
|
||||
func NewSignalCliApiConfig() *SignalCliApiConfig {
|
||||
|
||||
@@ -5,29 +5,29 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
Normal string = "NORMAL"
|
||||
Bold = "BOLD"
|
||||
Italic = "ITALIC"
|
||||
Monospace = "MONOSPACE"
|
||||
Strikethrough = "STRIKETHROUGH"
|
||||
Spoiler = "SPOILER"
|
||||
Normal string = "NORMAL"
|
||||
Bold = "BOLD"
|
||||
Italic = "ITALIC"
|
||||
Monospace = "MONOSPACE"
|
||||
Strikethrough = "STRIKETHROUGH"
|
||||
Spoiler = "SPOILER"
|
||||
)
|
||||
|
||||
const (
|
||||
None int = 0
|
||||
ItalicBegin = 1
|
||||
ItalicEnd = 2
|
||||
BoldBegin = 3
|
||||
BoldEnd1 = 4
|
||||
BoldEnd2 = 5
|
||||
MonoSpaceBegin = 6
|
||||
MonoSpaceEnd = 7
|
||||
StrikethroughBegin = 8
|
||||
StrikethroughEnd = 9
|
||||
SpoilerBegin1 = 10
|
||||
SpoilerBegin = 11
|
||||
SpoilerEnd1 = 12
|
||||
SpoilerEnd2 = 13
|
||||
None int = 0
|
||||
ItalicBegin = 1
|
||||
ItalicEnd = 2
|
||||
BoldBegin = 3
|
||||
BoldEnd1 = 4
|
||||
BoldEnd2 = 5
|
||||
MonoSpaceBegin = 6
|
||||
MonoSpaceEnd = 7
|
||||
StrikethroughBegin = 8
|
||||
StrikethroughEnd = 9
|
||||
SpoilerBegin1 = 10
|
||||
SpoilerBegin = 11
|
||||
SpoilerEnd1 = 12
|
||||
SpoilerEnd2 = 13
|
||||
)
|
||||
|
||||
func getUtf16CharacterCount(s string) int {
|
||||
@@ -35,7 +35,7 @@ func getUtf16CharacterCount(s string) int {
|
||||
if stringLength == 1 {
|
||||
return 1
|
||||
}
|
||||
return stringLength/2
|
||||
return stringLength / 2
|
||||
}
|
||||
|
||||
func getAdditionalCharacterCount(characterCount int) int {
|
||||
@@ -123,7 +123,7 @@ func ParseMarkdownMessage(message string) (string, []string) {
|
||||
lastChar = string(v)
|
||||
|
||||
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
|
||||
textFormatBegin = 0
|
||||
textFormatLength = 0
|
||||
|
||||
@@ -16,19 +16,19 @@ func expectFormatStringsEqual(t *testing.T, formatStrings1 []string, formatStrin
|
||||
}
|
||||
|
||||
func TestSimpleMessage1(t *testing.T) {
|
||||
message, signalCliFormatStrings := ParseMarkdownMessage("*italic*")
|
||||
message, signalCliFormatStrings := ParseMarkdownMessage("*italic*")
|
||||
expectMessageEqual(t, message, "italic")
|
||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"0:6:ITALIC"})
|
||||
}
|
||||
|
||||
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")
|
||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"0:24:ITALIC"})
|
||||
}
|
||||
|
||||
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")
|
||||
expectFormatStringsEqual(t, signalCliFormatStrings, []string{"10:4:BOLD", "19:6:ITALIC"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user