commit
532a4a9922
5 changed files with 170 additions and 0 deletions
@ -0,0 +1,74 @@ |
|||||
|
# Output |
||||
|
/messenger |
||||
|
|
||||
|
# dotenv |
||||
|
.env |
||||
|
|
||||
|
# VSCode |
||||
|
.vscode |
||||
|
|
||||
|
|
||||
|
# ---> Go |
||||
|
# Binaries for programs and plugins |
||||
|
*.exe |
||||
|
*.exe~ |
||||
|
*.dll |
||||
|
*.so |
||||
|
*.dylib |
||||
|
|
||||
|
# Test binary, built with `go test -c` |
||||
|
*.test |
||||
|
|
||||
|
# Output of the go coverage tool, specifically when used with LiteIDE |
||||
|
*.out |
||||
|
|
||||
|
# Dependency directories (remove the comment below to include it) |
||||
|
# vendor/ |
||||
|
|
||||
|
# ---> Vim |
||||
|
# Swap |
||||
|
[._]*.s[a-v][a-z] |
||||
|
!*.svg # comment out if you don't need vector files |
||||
|
[._]*.sw[a-p] |
||||
|
[._]s[a-rt-v][a-z] |
||||
|
[._]ss[a-gi-z] |
||||
|
[._]sw[a-p] |
||||
|
|
||||
|
# Session |
||||
|
Session.vim |
||||
|
Sessionx.vim |
||||
|
|
||||
|
# Temporary |
||||
|
.netrwhist |
||||
|
*~ |
||||
|
# Auto-generated tag files |
||||
|
tags |
||||
|
# Persistent undo |
||||
|
[._]*.un~ |
||||
|
|
||||
|
# ---> VisualStudioCode |
||||
|
.vscode/* |
||||
|
!.vscode/settings.json |
||||
|
!.vscode/tasks.json |
||||
|
!.vscode/launch.json |
||||
|
!.vscode/extensions.json |
||||
|
*.code-workspace |
||||
|
|
||||
|
# Local History for Visual Studio Code |
||||
|
.history/ |
||||
|
|
||||
|
# ---> Linux |
||||
|
*~ |
||||
|
|
||||
|
# temporary files which can be created if a process still has a handle open of a deleted file |
||||
|
.fuse_hidden* |
||||
|
|
||||
|
# KDE directory preferences |
||||
|
.directory |
||||
|
|
||||
|
# Linux trash folder which might appear on any partition or disk |
||||
|
.Trash-* |
||||
|
|
||||
|
# .nfs files are created when an open file is removed but is still being accessed |
||||
|
.nfs* |
||||
|
|
@ -0,0 +1,23 @@ |
|||||
|
# Messenger |
||||
|
|
||||
|
## About |
||||
|
The project's goal is build a generic messenger that notifies through multiple channels |
||||
|
|
||||
|
## Usage |
||||
|
``` |
||||
|
usage: print [-h|--help] [--webhook] [--url "<value>"] |
||||
|
|
||||
|
Prints provided string to stdout |
||||
|
|
||||
|
Arguments: |
||||
|
|
||||
|
-h --help Print help information |
||||
|
--webhook Use this flag to enable webhook sending |
||||
|
--url URL to be used for webhook |
||||
|
``` |
||||
|
|
||||
|
## Build |
||||
|
Use the following command to build the application: |
||||
|
``` |
||||
|
go build git.samuelpua.com/telboon/messenger/cmd/messenger |
||||
|
``` |
@ -0,0 +1,66 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"log" |
||||
|
"net/http" |
||||
|
"os" |
||||
|
"strings" |
||||
|
|
||||
|
"github.com/akamensky/argparse" |
||||
|
) |
||||
|
|
||||
|
func main() { |
||||
|
// Create new parser object
|
||||
|
parser := argparse.NewParser("print", "Prints provided string to stdout") |
||||
|
|
||||
|
// Create webhook flag
|
||||
|
webhookFlag := parser.Flag("", "webhook", &argparse.Options{Help: "Use this flag to enable webhook sending"}) |
||||
|
webhookURL := parser.String("", "url", &argparse.Options{Help: "URL to be used for webhook"}) |
||||
|
|
||||
|
// Parse input
|
||||
|
err := parser.Parse(os.Args) |
||||
|
if err != nil { |
||||
|
fmt.Print(parser.Usage(err)) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// Check inputs are set
|
||||
|
if *webhookFlag { |
||||
|
if webhookURL == nil || *webhookURL == "" { |
||||
|
fmt.Println("Webhook URL needs to be set if webhook is enabled.") |
||||
|
return |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Checks if at least one flag is enabled
|
||||
|
if *webhookFlag || false { |
||||
|
handleStdIn(webhookFlag, webhookURL) |
||||
|
} else { |
||||
|
fmt.Print(parser.Usage(err)) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func handleStdIn(webhookFlag *bool, webhookURL *string) { |
||||
|
for { |
||||
|
var currStr string |
||||
|
_, err := fmt.Scanf("%s", &currStr) |
||||
|
if err != nil { |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// Handle string
|
||||
|
if *webhookFlag { |
||||
|
err = sendWebhook(&currStr, webhookURL) |
||||
|
if err != nil { |
||||
|
log.Println(err) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func sendWebhook(currStr *string, webhookURL *string) error { |
||||
|
bodyReader := strings.NewReader(*currStr) |
||||
|
_, err := http.Post(*webhookURL, "text/plain", bodyReader) |
||||
|
return err |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
module git.samuelpua.com/telboon/messenger |
||||
|
|
||||
|
go 1.17 |
||||
|
|
||||
|
require github.com/akamensky/argparse v1.4.0 |
@ -0,0 +1,2 @@ |
|||||
|
github.com/akamensky/argparse v1.4.0 h1:YGzvsTqCvbEZhL8zZu2AiA5nq805NZh75JNj4ajn1xc= |
||||
|
github.com/akamensky/argparse v1.4.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA= |
Loading…
Reference in new issue