Skip to content

Commit

Permalink
make go mod as dependency manager
Browse files Browse the repository at this point in the history
  • Loading branch information
meysampg committed Aug 23, 2021
1 parent decf94c commit bf2f6e6
Show file tree
Hide file tree
Showing 43 changed files with 253 additions and 131 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Go

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Build
run: go build -v .
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# .github/workflows/release.yaml

name: Build Release
on:
release:
types: [ created ]

jobs:
releases-matrix:
name: Release Go Binary
runs-on: ubuntu-latest
strategy:
matrix:
goos: [ linux ]
goarch: [ "386", arm, amd64 ]
steps:
- uses: actions/checkout@v2

- name: Set APP_VERSION env
run: echo "APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev )" >> $GITHUB_ENV

- name: Set BUILD_TIME env
run: echo "BUILD_TIME=$(date --rfc-3339=seconds | sed 's/ /T/')" >> $GITHUB_ENV

- uses: wangyoucao577/go-release-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "https://dl.google.com/go/go1.15.2.linux-amd64.tar.gz"
project_path: "./"
binary_name: "callbacker"
extra_files: "README.md"
ldflags: -X "github.com/YasnaTeam/callbacker/configurator.AppVersion=${{ env.APP_VERSION }}" -X "github.com/YasnaTeam/callbacker/configurator.BuildTime=${{ env.BUILD_TIME }}" -X github.com/YasnaTeam/callbacker/configurator.GitCommit=${{ github.sha }} -s -w
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Callbacker :calling:

Callbacker is a utility for creating fake :hear_no_evil: callback URLs. Suppose you are working on a service which needs some callback calls from other services (like github or google). Then the main problem is getting callbacks on the `localhost` without any valid IP or URL :no_entry:. Callbacker is answer to that problem :ok_hand:.


Callbacker is a utility for creating fake :hear_no_evil: callback URLs. Suppose you are working on a service which needs
some callback calls from other services (like github or google). Then the main problem is getting callbacks on
the `localhost` without any valid IP or URL :no_entry:. Callbacker is answer to that problem :ok_hand:.

## Installing :computer:

### Direct method :arrow_double_down:

Get executable package from [latest release](https://github.com/YasnaTeam/callbacker/releases/latest) page and make it executable on your system.
Get executable package from [latest release](https://github.com/YasnaTeam/callbacker/releases/latest) page and make it
executable on your system.

### Via GO! :1st_place_medal:

Expand All @@ -18,17 +19,16 @@ Run this command
go get https://github.com/YasnaTeam/callbacker
```



## Terminology :arrow_heading_down:

Callbacker contains two part: `server` and `client`. `server` is one which register user connections, get their requests for callback definition and finally forward callback requests to `client`. `client` is the end user tools which can register callback, get forwarded request and send them to final destination.


Callbacker contains two part: `server` and `client`. `server` is one which register user connections, get their requests
for callback definition and finally forward callback requests to `client`. `client` is the end user tools which can
register callback, get forwarded request and send them to final destination.

### Running a `server` instance :construction_worker:

Suppose your final domain is `http://domain.ltd`, first you must define an endpoint with `/callback` URI. On `Nginx` you can do that with some configurations like this:
Suppose your final domain is `http://domain.ltd`, first you must define an endpoint with `/callback` URI. On `Nginx` you
can do that with some configurations like this:

```nginx
server {
Expand All @@ -46,8 +46,6 @@ then run the `server`:
./callbacker -v -s -u http://domain.ltd/callback
```



#### Defining a `systemd` service for server instance

For definition of a `systemd` service, you can create a file on `~/.config/systemd/user` and put this lines on it:
Expand All @@ -68,12 +66,8 @@ RestartSec=5s

then reload daemons with `systemctl daemon-reload` and run the service with `systemctl start callbacker`.



With `./callbacker -h` you can see all available flags.



### Running a `client` instance :post_office:

In your local command line, just run this:
Expand Down Expand Up @@ -102,7 +96,8 @@ Use this commands:
x (or exit) Exit from program
```
by pressing `a` you can add a local route to callbacker. Local route is an endpoint on your software which wanna receive information (for example from a github webhook or after logging in on google):
by pressing `a` you can add a local route to callbacker. Local route is an endpoint on your software which wanna receive
information (for example from a github webhook or after logging in on google):
```bash
$ ./callbacker -c domain.ltd:2424
Expand All @@ -123,10 +118,13 @@ Please select a command (Press h for help): l
1 http://mysite.mpg/api/v1/my_endpoint http://domain.ltd/callback/b5b1c30a-57e2-428e-861e-813d9a92fc0f
```
Now you can use `http://domain.ltd/callback/b5b1c30a-57e2-428e-861e-813d9a92fc0f` as a valid URL and pass it to origin (e.g. github webhook, ...). Each time a callback has been called to this URL, all information of request will be sent to your running client and a callback will be simulated.
Now you can use `http://domain.ltd/callback/b5b1c30a-57e2-428e-861e-813d9a92fc0f` as a valid URL and pass it to origin (
e.g. github webhook, ...). Each time a callback has been called to this URL, all information of request will be sent to
your running client and a callback will be simulated.
## Contribution :love_letter:
Fork from this project :fork_and_knife:,use [glide](http://glide.sh/) as package manager, do your modification and send a pull request! Also all issues are welcome! :heart:
Fork from this project :fork_and_knife:, do your modification and send a pull request!
---------
Made with love in [YasnaTeam](https://yasna.team) :heart:
4 changes: 2 additions & 2 deletions client/Configuration.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package client

import (
"os"
"encoding/json"
"os"
)

type Configuration struct {
Expand Down Expand Up @@ -78,4 +78,4 @@ func saveConfiguration(configuration *Configuration) error {
}

return nil
}
}
5 changes: 3 additions & 2 deletions client/HttpClient.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package client

import (
"bytes"
"net/http"

"github.com/YasnaTeam/callbacker/common"
"github.com/gojektech/heimdall/httpclient"
"net/http"
"bytes"
)

type Client struct {
Expand Down
7 changes: 4 additions & 3 deletions client/Initialize.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package client

import (
"github.com/sirupsen/logrus"
"net"

"github.com/YasnaTeam/callbacker/storage"
"github.com/sirupsen/logrus"
)

var log *logrus.Logger
var username string
var routes storage.RouteTable // map callback url to route
var configuration *Configuration

func Initialize(address string, logger *logrus.Logger, notification func (title, text string)) {
func Initialize(address string, logger *logrus.Logger, notification func(title, text string)) {
log = logger
log.Info("Client started...")

Expand Down Expand Up @@ -41,7 +42,7 @@ func Initialize(address string, logger *logrus.Logger, notification func (title,
} else {
log.Debugf("User `%s` has been selected from configurations file.", configuration.Username)
registerUserOnServer(conn, configuration.Username)
setSavedCallbacksOnClientRouteTable();
setSavedCallbacksOnClientRouteTable()
}

// All receiving of data is handled by this function
Expand Down
5 changes: 3 additions & 2 deletions client/Notification.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package client

import (
"runtime"
"os/exec"
"fmt"
"os/exec"
"runtime"

"github.com/sirupsen/logrus"
)

Expand Down
2 changes: 1 addition & 1 deletion client/addCallbackInformation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package client

func addCallbackInformation(result, route string, notification func (title, text string)) {
func addCallbackInformation(result, route string, notification func(title, text string)) {
routes.Set(result, route)
configuration.AddRouteCallback(route, result)

Expand Down
3 changes: 2 additions & 1 deletion client/callCallbackOnRecieveDataFromServer.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package client

import (
"fmt"
"net"

"github.com/YasnaTeam/callbacker/common"
"fmt"
)

func callCallbackOnRecieveDataFromServer(conn net.Conn) {
Expand Down
5 changes: 3 additions & 2 deletions client/doActionOnReceivingDataFromServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package client

import (
"net"
"github.com/YasnaTeam/callbacker/common"
"os"

"github.com/YasnaTeam/callbacker/common"
)

func doActionOnReceivingDataFromServer(conn net.Conn, notification func (title, text string)) {
func doActionOnReceivingDataFromServer(conn net.Conn, notification func(title, text string)) {
for {
packet, err := common.ReceiveDataFromConnection(conn)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions client/doRequestPacketAction.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package client

import (
"github.com/YasnaTeam/callbacker/common"
"net"

"github.com/YasnaTeam/callbacker/common"
)

func doRequestPacketAction(conn net.Conn, tr *common.TransferableRequest, notification func (title, text string)) {
func doRequestPacketAction(conn net.Conn, tr *common.TransferableRequest, notification func(title, text string)) {
data := tr.GetData().(*common.Request)
switch tr.GetCommand() {
case "callback_forward":
Expand Down
5 changes: 3 additions & 2 deletions client/doRouteCallbackPacketAction.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package client

import (
"github.com/YasnaTeam/callbacker/common"
"net"

"github.com/YasnaTeam/callbacker/common"
)

func doRouteCallbackPacketAction(conn net.Conn, rc *common.TransferableRouteCallback, domain string, notification func (title, text string)) {
func doRouteCallbackPacketAction(conn net.Conn, rc *common.TransferableRouteCallback, domain string, notification func(title, text string)) {
data := rc.GetData().(*common.RouteCallback)
switch rc.GetCommand() {
case "callback_information":
Expand Down
5 changes: 3 additions & 2 deletions client/doStringPacketAction.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package client

import (
"github.com/YasnaTeam/callbacker/common"
"net"

"github.com/YasnaTeam/callbacker/common"
)

func doStringPacketAction(conn net.Conn, ts *common.TransferableString, notification func (title, text string)) {
func doStringPacketAction(conn net.Conn, ts *common.TransferableString, notification func(title, text string)) {
//data := ts.GetData().(string)
switch ts.GetCommand() {
case "register_user":
Expand Down
2 changes: 1 addition & 1 deletion client/getAndRegisterUserOnServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package client

import (
"bufio"
"os"
"fmt"
"net"
"os"
)

func getAndRegisterUserOnServer(conn net.Conn) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions client/getUserCommandsAndSendThemToServer.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package client

import (
"net"
"bufio"
"os"
"fmt"
"net"
"os"
)

func getUserCommandsAndSendThemToServer(conn net.Conn) {
Expand Down
4 changes: 2 additions & 2 deletions client/listUserRoutesAndCallbacksInATable.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package client

import (
"text/tabwriter"
"os"
"fmt"
"os"
"text/tabwriter"
)

func listUserRoutesAndCallbacksInATable() {
Expand Down
1 change: 1 addition & 0 deletions client/registerUserConnectionOnServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"net"

"github.com/YasnaTeam/callbacker/common"
)

Expand Down
5 changes: 3 additions & 2 deletions client/sendRequestToLocalRoute.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package client

import (
"github.com/YasnaTeam/callbacker/common"
"fmt"

"github.com/YasnaTeam/callbacker/common"
)

func sendRequestToLocalRoute(r *common.Request, notification func (title, text string)) {
func sendRequestToLocalRoute(r *common.Request, notification func(title, text string)) {
hc := NewHttpClient(r)
err := hc.SendRequest()

Expand Down
1 change: 1 addition & 0 deletions client/syncCallbackInformationWithServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"net"

"github.com/YasnaTeam/callbacker/common"
)

Expand Down
2 changes: 1 addition & 1 deletion common/GetInformationOfRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ func generateCallback(domain, callback string) string {
callbackInformation := strings.Split(callback, "/")

return domain + "/" + callbackInformation[1]
}
}
3 changes: 2 additions & 1 deletion common/PrepareRequestToSend.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package common

import (
"vuvuzela.io/alpenhorn/log"
"net/http"

"vuvuzela.io/alpenhorn/log"
)

func PrepareRequestToSend(r *http.Request, domain string) ([]byte, error) {
Expand Down
Loading

0 comments on commit bf2f6e6

Please sign in to comment.