asyncnetworkengine

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 13 Imported by: 0

README

Async Network Engine Go

Unity http requests made easy to interoperability with Go Lang + Google Protobuf functions!

Supported Cloud Functions:

  • Google Cloud Functions
  • Amazon Web Services Lambdas

Use at your own risk!

Repository

Async Network Engine Go is a go module developed side-by-side with UnityEngine open-source module Async Network Engine. Is intended to be used together, but it suitable be used with any custom GoogleProtobuf client.

How to install

At go.mod, add async network engine:

module example.com/module

go 1.13

require github.com/GameWorkstore/async-network-engine-go v0.1.3

and execute

go mod tidy

to download it into your machine. or use

go get github.com/GameWorkstore/async-network-engine-go

on the case want to use it in many projects.

Implementation

GCP Troubleshoot

My function is returning ErrorProtocol for any input. if you don't give access public for your function it might fail

AWS Troubleshoot

CloudFormation is returning errors

Verify all variables, !Ref and links, you might be forgetting something. CloudFormations is very sensitive to linkage errors.

My lambda is returning error 500 Internal Server error. If you are receiving this and error object is returning null, it might be a bad configuration causing your lambda to not run. Verify if you function is running by adding a fmt.Println("test") at main() function to ensure the function is starting. Some issues that may prevent the start of function:

  • The functions ins't at correct path when extracted from the zip.
  • The function package name isn't main where main() function is declared.
  • lambda.Start() is never begin called to initialize the function.
  • The function is crashing upon initialization

If the function is working normally, them you might receive error 500 - ErrorInternalServer with AWSError, when specified by the programmer.

Future Work

Integrate with gRPC may be the natural evolution of this package, but it's production ready at current state.

Contributions

If you are using this library and want to submit a change, go ahead! Overall, this project accepts contributions if:

  • Is a bug fix;
  • Or, is a generalization of a well-known issue;
  • Or is performance improvement;
  • Or is an improvement to already supported feature.

Also, you can donate to allow us to drink coffee while we improve it for you!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Transmission_name = map[int32]string{
		0:   "NotSpecified",
		1:   "ErrorConnection",
		2:   "ErrorProtocol",
		3:   "ErrorParser",
		200: "Success",
		204: "ErrorNoData",
		400: "ErrorDecode",
		401: "ErrorUnauthorized",
		403: "ErrorForbidden",
		405: "ErrorMethodNotAllowed",
		408: "ErrorRequestTimeout",
		421: "ErrorEncode",
		500: "ErrorInternalServer",
		501: "ErrorNotImplemented",
		511: "ErrorNetworkAuthenticationRequired",
	}
	Transmission_value = map[string]int32{
		"NotSpecified":                       0,
		"ErrorConnection":                    1,
		"ErrorProtocol":                      2,
		"ErrorParser":                        3,
		"Success":                            200,
		"ErrorNoData":                        204,
		"ErrorDecode":                        400,
		"ErrorUnauthorized":                  401,
		"ErrorForbidden":                     403,
		"ErrorMethodNotAllowed":              405,
		"ErrorRequestTimeout":                408,
		"ErrorEncode":                        421,
		"ErrorInternalServer":                500,
		"ErrorNotImplemented":                501,
		"ErrorNetworkAuthenticationRequired": 511,
	}
)

Enum value maps for Transmission.

View Source
var File_asyncrpc_proto protoreflect.FileDescriptor

Functions

func AWSDecode

AWSDecode decodes and returns the protobuf of given connection. Return to gateway (response,nil) if err != nil.

func AWSError

func AWSError(status Transmission, err error) (events.APIGatewayProxyResponse, error)

AWSError writes an error response in given connection.

func AWSResponse

AWSResponse writes response in given connection.

func CreateToken

func CreateToken(pb proto.Message) (string, error)

CreateToken creates a token for an given user

func EnableCORS

func EnableCORS()

EnableCORS setup default CORS to enabled.

func GCPDecode

func GCPDecode(r *http.Request, w http.ResponseWriter, rqt proto.Message) bool

GCPDecode decodes and returns the protobuf of given connection. returns true if break by OPTIONS or error.

func GCPError

func GCPError(w http.ResponseWriter, status Transmission, err error)

GCPError writes an error response in given connection.

func GCPResponse

func GCPResponse(w http.ResponseWriter, pb proto.Message)

GCPResponse writes response in given connection.

func SetupCORS

func SetupCORS(allowCredentials bool, allowOrigin string, allowHeaders string, allowMethods string, maxAge int)

SetupCORS enable CORS and configures AsyncNetworkEngine to accept methods, headers and etc from a given application. For more information about CORS and CORS preflight requests, see https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request.

func SetupHS256Token added in v0.4.0

func SetupHS256Token(issuer string, key string, maxAge time.Duration)

func SetupToken

func SetupToken(method jwt.SigningMethod, issuer string, key interface{}, maxAge time.Duration)

SetupToken setup function to emit and validate tokens on behalf of the user in doubt about maxAge, use time.Hour

func ValidateToken

func ValidateToken(sessionToken string, pb proto.Message) error

ValidateToken validates a token return the user structure

Types

type GenericErrorResponse

type GenericErrorResponse struct {
	Error string `protobuf:"bytes,1,opt,name=Error,proto3" json:"Error,omitempty"`
	// contains filtered or unexported fields
}

func (*GenericErrorResponse) Descriptor deprecated

func (*GenericErrorResponse) Descriptor() ([]byte, []int)

Deprecated: Use GenericErrorResponse.ProtoReflect.Descriptor instead.

func (*GenericErrorResponse) GetError

func (x *GenericErrorResponse) GetError() string

func (*GenericErrorResponse) ProtoMessage

func (*GenericErrorResponse) ProtoMessage()

func (*GenericErrorResponse) ProtoReflect

func (x *GenericErrorResponse) ProtoReflect() protoreflect.Message

func (*GenericErrorResponse) Reset

func (x *GenericErrorResponse) Reset()

func (*GenericErrorResponse) String

func (x *GenericErrorResponse) String() string

type GenericRequest

type GenericRequest struct {
	Messege string `protobuf:"bytes,1,opt,name=Messege,proto3" json:"Messege,omitempty"`
	// contains filtered or unexported fields
}

func (*GenericRequest) Descriptor deprecated

func (*GenericRequest) Descriptor() ([]byte, []int)

Deprecated: Use GenericRequest.ProtoReflect.Descriptor instead.

func (*GenericRequest) GetMessege

func (x *GenericRequest) GetMessege() string

func (*GenericRequest) ProtoMessage

func (*GenericRequest) ProtoMessage()

func (*GenericRequest) ProtoReflect

func (x *GenericRequest) ProtoReflect() protoreflect.Message

func (*GenericRequest) Reset

func (x *GenericRequest) Reset()

func (*GenericRequest) String

func (x *GenericRequest) String() string

type GenericResponse

type GenericResponse struct {
	Messege string `protobuf:"bytes,2,opt,name=Messege,proto3" json:"Messege,omitempty"`
	// contains filtered or unexported fields
}

func (*GenericResponse) Descriptor deprecated

func (*GenericResponse) Descriptor() ([]byte, []int)

Deprecated: Use GenericResponse.ProtoReflect.Descriptor instead.

func (*GenericResponse) GetMessege

func (x *GenericResponse) GetMessege() string

func (*GenericResponse) ProtoMessage

func (*GenericResponse) ProtoMessage()

func (*GenericResponse) ProtoReflect

func (x *GenericResponse) ProtoReflect() protoreflect.Message

func (*GenericResponse) Reset

func (x *GenericResponse) Reset()

func (*GenericResponse) String

func (x *GenericResponse) String() string

type Transmission

type Transmission int32
const (
	Transmission_NotSpecified                       Transmission = 0
	Transmission_ErrorConnection                    Transmission = 1
	Transmission_ErrorProtocol                      Transmission = 2
	Transmission_ErrorParser                        Transmission = 3
	Transmission_Success                            Transmission = 200 // StatusOK
	Transmission_ErrorNoData                        Transmission = 204 //StatusNoContent
	Transmission_ErrorDecode                        Transmission = 400 //StatusBadRequest
	Transmission_ErrorUnauthorized                  Transmission = 401 //Unauthorized
	Transmission_ErrorForbidden                     Transmission = 403 //Forbidden
	Transmission_ErrorMethodNotAllowed              Transmission = 405 //StatusMethodNotAllowed
	Transmission_ErrorRequestTimeout                Transmission = 408 //StatusRequestTimeout
	Transmission_ErrorEncode                        Transmission = 421 //Misdirected Request
	Transmission_ErrorInternalServer                Transmission = 500 //StatusInternalServerError
	Transmission_ErrorNotImplemented                Transmission = 501 //StatusNotImplemented
	Transmission_ErrorNetworkAuthenticationRequired Transmission = 511 //NetworkAuthenticationRequired
)

func (Transmission) Descriptor

func (Transmission) Enum

func (x Transmission) Enum() *Transmission

func (Transmission) EnumDescriptor deprecated

func (Transmission) EnumDescriptor() ([]byte, []int)

Deprecated: Use Transmission.Descriptor instead.

func (Transmission) Number

func (Transmission) String

func (x Transmission) String() string

func (Transmission) Type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL