go-lang (#1)
Reviewed-on: phoenix/twilio_sender#1 Co-authored-by: kdeng00 <kundeng94@gmail.com> Co-committed-by: kdeng00 <kundeng94@gmail.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package util
|
||||
|
||||
import "encoding/json"
|
||||
import "fmt"
|
||||
import "os"
|
||||
import "strings"
|
||||
|
||||
import (
|
||||
"git.kundeng.us/phoenix/twilio_sender/models"
|
||||
)
|
||||
|
||||
func GetPaths(args []string) (configPath string, numberPath string, messagePath string) {
|
||||
configPath = args[1]
|
||||
numberPath = args[2]
|
||||
messagePath = args[3]
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func ParseNumbers(filepath string) (numbers [](models.Number)) {
|
||||
nmbrs := [](string){}
|
||||
|
||||
content, err := os.ReadFile(filepath)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("An error occurred")
|
||||
return numbers
|
||||
}
|
||||
|
||||
err = json.Unmarshal(content, &nmbrs)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("An error occurred")
|
||||
return numbers
|
||||
}
|
||||
|
||||
for _, nbr := range nmbrs {
|
||||
var number models.Number
|
||||
number.PhoneNumber = nbr
|
||||
numbers = append(numbers, number)
|
||||
}
|
||||
|
||||
return numbers
|
||||
}
|
||||
|
||||
func ParseMessage(filepath string) (message models.Message) {
|
||||
msg := [](string){""}
|
||||
|
||||
content, err := os.ReadFile(filepath)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("An error occurred")
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(content, &msg)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("An error occurred")
|
||||
return
|
||||
}
|
||||
|
||||
message.Text = strings.Join(msg, "")
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user