-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: common package [DTSS-595] (#115)
- Loading branch information
1 parent
c4b0e2f
commit 57b709c
Showing
4 changed files
with
58 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Package localizer is meant to contain useful helper functions, variables, and | ||
// constants in order to better programatically interact with localizer. | ||
package localizer | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
apiv1 "github.com/getoutreach/localizer/api/v1" | ||
"github.com/pkg/errors" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// Socket is the communication endpoint that the localizer server is listening | ||
// on. | ||
const Socket = "/var/run/localizer.sock" | ||
|
||
// IsRunning checks to see if the localizer socket exists. | ||
func IsRunning() bool { | ||
if _, err := os.Stat(Socket); err != nil { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
// Connect returns a new instance of LocalizerServiceClient given a gRPC client | ||
// connection (returned from grpc.Dial*). | ||
func Connect(ctx context.Context, opts ...grpc.DialOption) (apiv1.LocalizerServiceClient, error) { | ||
clientConn, err := grpc.DialContext(ctx, fmt.Sprintf("unix://%s", Socket), opts...) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "dial localizer") | ||
} | ||
|
||
return apiv1.NewLocalizerServiceClient(clientConn), nil | ||
} |