Skip to content

Commit

Permalink
Merge pull request #3 from madflojo/src
Browse files Browse the repository at this point in the history
feat: getting ready for initial Go SDK
  • Loading branch information
madflojo authored Oct 6, 2024
2 parents 3764129 + 808e37c commit da705a0
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 37 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ on:
- main
pull_request:

shell: bash
defaults:
run:
shell: bash

jobs:
lint:
Expand All @@ -33,6 +35,10 @@ jobs:
go-version: '1.21'
- name: Install protoc-gen-go
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
- name: Install protoc-gen-go-vtproto
run: go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@latest

- name: generate language files
run: make all clean
run: make build clean
env:
GOPATH: /home/runner/go
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ OUT_DIR=build
# Go-specific settings
GO_OUT=$(OUT_DIR)/go

.PHONY: all clean go
.PHONY: build clean go

all: go
build: go

go:
@echo "Generating Go code..."
mkdir -p $(GO_OUT)
protoc -I=./proto --go_out=$(GO_OUT) ./proto/*.proto
@echo "Generating SDK..."
protoc -I=./sdk --go_out=$(GO_OUT) --go-vtproto_out=$(GO_OUT) --plugin protoc-gen-go="${GOPATH}/bin/protoc-gen-go" --plugin protoc-gen-go-vtproto="${GOPATH}/bin/protoc-gen-go-vtproto" ./sdk/*.proto

clean:
@echo "Cleaning up generated files..."
Expand Down
25 changes: 0 additions & 25 deletions proto/sql.proto

This file was deleted.

9 changes: 8 additions & 1 deletion proto/http.proto → sdk/http.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ syntax = "proto3";
package tarmac.http;

import "tarmac.proto";
option go_package = "github.com/tarmac-project/tarmac/proto";
option go_package = "github.com/tarmac-project/protobuf-go/sdk/http";

// HTTPClient is a structure used to create HTTP calls to remote systems.
message HTTPClient {
// Method is the HTTP method type for the HTTP request; valid options are
// GET, POST, PUT, PATCH, HEAD, & DELETE.
string method = 1;

// Headers are the HTTP headers to include in the HTTP request.
map<string, string> headers = 2;

// URL is the HTTP URL to call.
string url = 3;

// Body is the user-supplied HTTP body data. This field should contain the
// request payload data.
bytes body = 4;

// Insecure will disable TLS host verification; this is common with
// self-signed certificates; however, use caution.
bool insecure = 5;
Expand All @@ -28,10 +32,13 @@ message HTTPClientResponse {
// Status is the human readable error message or success message for function
// execution.
tarmac.Status status = 1;

// Code is the HTTP Status Code returned from the target server.
int32 code = 2;

// Headers are the HTTP headers returned from the HTTP request.
map<string, string> headers = 3;

// Body is the server-supplied HTTP payload data. The server-supplied payload
// will be a byte slice.
bytes body = 4;
Expand Down
20 changes: 18 additions & 2 deletions proto/kvstore.proto → sdk/kvstore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ syntax = "proto3";
package tarmac.kvstore;

import "tarmac.proto";
option go_package = "github.com/tarmac-project/tarmac/proto";
option go_package = "github.com/tarmac-project/protobuf-go/sdk/kvstore";

// KVStoreGet is a structure used to create Get request callbacks to the Tarmac
// KVStore interface.
Expand All @@ -24,6 +24,7 @@ message KVStoreGetResponse {
// Status is the human readable error message or success message for function
// execution.
tarmac.Status status = 1;

// Data is the response data provided by the key:value store.
// This data is a byte slice to provide a simple field for arbitrary data.
bytes data = 2;
Expand All @@ -37,6 +38,7 @@ message KVStoreGetResponse {
message KVStoreSet {
// Key is the index key used to store the data.
string key = 1;

// Data is the user-supplied key:value data.
// Tarmac expects this field to be a byte slice.
bytes data = 2;
Expand Down Expand Up @@ -74,15 +76,29 @@ message KVStoreDeleteResponse {
tarmac.Status status = 1;
}

// KVStoreKeys is a structure used to create a Keys callback request to the
// Tarmac KVStore interface.
//
// This structure is a general request type used for all KVStore types provided
// by Tarmac.
message KVStoreKeys {
// ReturnProto is a boolean value that determines if the response should be
// returned as a JSON string or as a KVStoreKeysResponse message.
//
// This must be set to true to return a KVStoreKeysResponse message.
bool return_proto = 1;
}

// KVStoreKeysResponse is a structure supplied as a response message to the
// KVStore Keys callback function.

//
// This response is a general response type used for all KVStore types provided
// by Tarmac.
message KVStoreKeysResponse {
// Status is the human readable error message or success message for function
// execution.
tarmac.Status status = 1;

// Keys is a list of keys available within the KV Store.
repeated string keys = 2;
}
5 changes: 3 additions & 2 deletions proto/metrics.proto → sdk/metrics.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
syntax = "proto3";

package tarmac.metrics;

option go_package = "github.com/tarmac-project/tarmac/proto";
option go_package = "github.com/tarmac-project/protobuf-go/sdk/metrics";

// MetricsCounter is a structure used to create Counter metrics callback
// requests to the Tarmac Metrics interface.
Expand All @@ -16,6 +15,7 @@ message MetricsCounter {
message MetricsGauge {
// Name is the name of the metric as exposed via the metrics HTTP end-point.
string name = 1;

// Action is the action to be performed for the Gauge metric.
// Valid options are inc (Increment) and dec (Decrement).
string action = 2; // inc or dec
Expand All @@ -26,6 +26,7 @@ message MetricsGauge {
message MetricsHistogram {
// Name is the name of the metric as exposed via the metrics HTTP end-point.
string name = 1;

// Value is the value to Observe for the Histogram metric.
double value = 2;
}
54 changes: 54 additions & 0 deletions sdk/sql.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
syntax = "proto3";

package tarmac.sql;

import "tarmac.proto";
option go_package = "github.com/tarmac-project/protobuf-go/sdk/sql";

// SQLExec is a structure used to execute a SQL query on a SQL Database.
// This message type should be leveraged for queries that do not return rows.
message SQLExec {
// Query is the SQL Query to be executed. This field should be a byte slice
// to avoid conflicts with JSON encoding.
bytes query = 1;
}

// SQLExecResponse is a structure supplied as a response message to a SQLExec
// request.
message SQLExecResponse {
// Status is the human readable error message or success message for function
// execution.
tarmac.Status status = 1;

// LastInsertID is the ID of the last inserted row. This field is only
// populated if the query was an insert query and the database supports
// returning the last inserted ID.
int64 last_insert_id = 2;

// RowsAffected is the number of rows affected by the query. This field is
// only populated if the query was an insert, update, or delete query.
int64 rows_affected = 3;
}

// SQLQuery is a structure used to create SQL queries to a SQL Database.
message SQLQuery {
// Query is the SQL Query to be executed. This field should be a byte slice
// to avoid conflicts with JSON encoding.
bytes query = 1;
}

// SQLQueryResponse is a structure supplied as a response message to a SQL
// Database Query.
message SQLQueryResponse {
// Status is the human readable error message or success message for function
// execution.
tarmac.Status status = 1;

// Columns is a list of column names returned by the query. This field is
// only populated if the query was a select query.
repeated string columns = 4;

// Data is a JSON encoded byte slice of the data returned by the query.
bytes data = 5;
}

4 changes: 2 additions & 2 deletions proto/tarmac.proto → sdk/tarmac.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
syntax = "proto3";

package tarmac;

option go_package = "github.com/tarmac-project/tarmac/proto";
option go_package = "github.com/tarmac-project/protobuf-go/sdk";

// Status is used to return a status code and message to clients when
// performing host callbacks to Tarmac.
Expand All @@ -16,6 +15,7 @@ option go_package = "github.com/tarmac-project/tarmac/proto";
message Status {
// Code is the status code for callback execution.
int32 code = 1;

// Status is the human readable error message or success message for function
// execution.
string status = 2;
Expand Down

0 comments on commit da705a0

Please sign in to comment.