golib

package module
v0.0.0-...-608f34f Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AGW200

func AGW200(body string, headers map[string]string) events.APIGatewayV2HTTPResponse

AGW200 returns a agi gw v2 success response

func AGW400

AGW400 returns a error agi gw v2 response

func AGW404

AGW404 returns a error agi gw v2 response

func AGW500

AGW500 returns a error agi gw v2 response

func AffixIDsToString

func AffixIDsToString(levelTwoID, levelFourID, levelSevenID, levelTenID int) string

AffixIDsToString takes an array of affix ids and converts them to a readable list of array names separated by commas TODO:

  • rethink if I actually need this, displaying a list of affixes as string takes a lot of space, should just return an array of ids and string and display icons and display the name on hover

func Atoi64

func Atoi64(input string) (int64, error)

Atoi64 is just a small wrapper around ParseInt

func CanonicalLog

func CanonicalLog(msg map[string]interface{})

CanonicalLog writes a structured message to stdout if the log level is atleast INFO

func Contains

func Contains(slice []string, el string) bool

Contains checks if a slice of strings contains a specific string as an element

func DownloadS3

func DownloadS3(ctx aws.Context, downloader *s3manager.Downloader, bucketName string, objectKey string, fileContent io.WriterAt) error

DownloadS3 downloads a file from s3

func DynamoDBGetItem

func DynamoDBGetItem(ctx aws.Context, svc *dynamodb.DynamoDB, input *dynamodb.GetItemInput) (*dynamodb.GetItemOutput, error)

DynamoDBGetItem gets a single item from dynamodb and always returns consumed capacity

func DynamoDBPutItem

func DynamoDBPutItem(ctx aws.Context, svc *dynamodb.DynamoDB, ddbTableName *string, record interface{}) (*dynamodb.PutItemOutput, error)

DynamoDBPutItem writes a single item to dynamodb and always returns consumed capacity. just pass in a struct for record it will be converted to a ddb type, make sure the struct as the json tags that reflect the name in ddb, such as pk and sk

func DynamoDBQuery

func DynamoDBQuery(ctx aws.Context, svc *dynamodb.DynamoDB, input dynamodb.QueryInput) (*dynamodb.QueryOutput, error)

DynamoDBQuery is a helper to simplify querying a dynamo db table

func InitLogging

func InitLogging()

InitLogging sets up the logging for every lambda and should be called before the handler

func KeysResponseToJson

func KeysResponseToJson(result *dynamodb.QueryOutput, sorted, firstPage bool) (string, error)

KeysResponseToJson takes a dynamodb query output and converts it to be consumed by the frontend mostly it makes sure the pagination works correctly this is used for top keys and top keys per dungeon

func KeysToJson

func KeysToJson(result *dynamodb.QueryOutput) (string, error)

KeysToJson is unused right now, I think it was the predecessor of KeysResponseToJson

func MinSecToMilliseconds

func MinSecToMilliseconds(input string) (int64, error)

MinSecToMilliseconds converts time in the "minute:seconds" format to milliseconds

func PlayerDamageDoneToJson

func PlayerDamageDoneToJson(result *dynamodb.GetItemOutput) (string, error)

PlayerDamageDoneToJson returns the log specific damage result, including damage per spell breakdown, both damage per player and per spell are sorted before saving to the db. We don't need an extra JSON struct, like for keys, because there is no pagination etc.

func PrettyStruct

func PrettyStruct(input interface{}) (string, error)

PrettyStruct converts a struct, slice of a struct or map into a readable string

func RenameFileS3

func RenameFileS3(ctx aws.Context, s3Svc *s3.S3, oldName, newName, bucketName string) error

RenameFileS3 creates a copy of a file and deletes the old one, because you can't rename files =(

func SNSPublishMsg

func SNSPublishMsg(ctx aws.Context, snsSvc *sns.SNS, input string, topicArn *string) error

SNSPublishMsg publishes a message to an SNS topic

func SizeOfS3Object

func SizeOfS3Object(ctx aws.Context, s3Svc *s3.S3, bucketName string, objectKey string) (int, error)

SizeOfS3Object checks the file size without actually downloading it in KB

func TimeMessageInQueue

func TimeMessageInQueue(e SQSEvent, i int) error

TimeMessageInQueue IMPROVE: only pass in pointer to SQSEvent we can see an overall trend of this in the SQS metrics, I created this to double check how fast messages are polled with fargate, but since I use lambda the lambda service takes care of this and messages are usually only 10ms old before they are pushed into lambda

func TimedAsPercent

func TimedAsPercent(dungeonID int, durationInMilliseconds float64) (durAsPercent float64, intime int, err error)

TimedAsPercent determines if a key was intime, deplete, two chest or three chest and returns the quotient of the expected intime duration and the actual duration in milliseconds this is used to order the keys, so the fastest within a key level is first TODO: add table test and check 0 duration

func TimestreamQuery

func TimestreamQuery(ctx aws.Context, query *string, querySvc *timestreamquery.TimestreamQuery) (*timestreamquery.QueryOutput, error)

TimestreamQuery runs a query against timestream and checks if the query is already finished. timestream returns a response after ~6 seconds even if it is not finished. It checks the NextToken and reruns the query if need be

func WriteToTimestream

WriteToTimestream takes a slice of records to write and writes batches of 100 records to timestream

Types

type DamagePerSpell

type DamagePerSpell struct {
	SpellID   int    `json:"spell_id"`
	SpellName string `json:"spell_name"`
	Damage    int64  `json:"damage"`
}

DamagePerSpell is a part of PlayerDamageDone and contains the breakdown of damage per spell

type DynamoDBKeys

type DynamoDBKeys struct {
	Pk            string         `json:"pk"`
	Sk            string         `json:"sk"`
	Damage        []PlayerDamage `json:"player_damage"`
	Gsi1pk        string         `json:"gsi1pk"`
	Gsi1sk        string         `json:"gsi1sk"`
	Duration      string         `json:"duration"`
	Deaths        int            `json:"deaths"`
	Affixes       string         `json:"affixes"`
	Keylevel      int            `json:"keylevel"`
	DungeonName   string         `json:"dungeon_name"`
	DungeonID     int            `json:"dungeon_id"`
	CombatlogHash string         `json:"combatlog_hash"`
	Finished      bool           `json:"finished"`
	Intime        int            `json:"intime"`
	Date          int64          `json:"date"`
	CreatedAt     string         `json:"created_at"`
}

DynamoDBKeys is used to display the top keys and top keys per dungeon

type DynamoDBPlayerDamageDone

type DynamoDBPlayerDamageDone struct {
	Pk            string             `json:"pk"`
	Sk            string             `json:"sk"`
	Damage        []PlayerDamageDone `json:"player_damage"`
	Duration      string             `json:"duration"`
	Deaths        int                `json:"deaths"`
	Affixes       string             `json:"affixes"`
	Keylevel      int                `json:"keylevel"`
	DungeonName   string             `json:"dungeon_name"`
	DungeonID     int                `json:"dungeon_id"`
	CombatlogHash string             `json:"combatlog_hash"`
	Finished      bool               `json:"finished"`
	Intime        int                `json:"intime"`
	Date          int64              `json:"date"`
	CreatedAt     string             `json:"created_at"`
}

DynamoDBPlayerDamageDone is used to save player damage done to dynamodb, log specific view

type DynamodbDedup

type DynamodbDedup struct {
	Pk        string `json:"pk"`
	Sk        string `json:"sk"`
	CreatedAt string `json:"created_at"`
}

DynamodbDedup is used to save if a Combatlog has already been uploaded to timestream Pk: fmt.Sprintf("DEDUP#%d", hash), Sk: fmt.Sprintf("DEDUP#%d", hash),

type JSONKeys

type JSONKeys struct {
	Damage        []PlayerDamage `json:"player_damage"`
	Duration      string         `json:"duration"`
	Deaths        int            `json:"deaths"`
	Affixes       string         `json:"affixes"`
	Keylevel      int            `json:"keylevel"`
	DungeonName   string         `json:"dungeon_name"`
	DungeonID     int            `json:"dungeon_id"`
	CombatlogHash string         `json:"combatlog_hash"`
	Intime        int            `json:"intime"`
}

type JSONKeysResponse

type JSONKeysResponse struct {
	Data      []JSONKeys `json:"data"`
	FirstSK   string     `json:"first_sk"`
	LastSK    string     `json:"last_sk"`
	FirstPage bool       `json:"first_page"`
	LastPage  bool       `json:"last_page"`
}

type PlayerDamage

type PlayerDamage struct {
	Damage   int    `json:"damage"` // TODO: convert to int64
	Name     string `json:"player_name"`
	PlayerID string `json:"player_id"`
	Class    string `json:"class"`
	Specc    string `json:"specc"`
}

PlayerDamage contains player and damage info for the top keys view etc.

type PlayerDamageDone

type PlayerDamageDone struct {
	Damage         int64            `json:"damage"`
	DamagePerSpell []DamagePerSpell `json:"damage_per_spell"`
	Name           string           `json:"player_name"`
	PlayerID       string           `json:"player_id"`
	Class          string           `json:"class"`
	Specc          string           `json:"specc"`
}

PlayerDamageDone contains player and damage per spell info for the log specific view

type S3Event

type S3Event struct {
	Records []struct {
		S3 struct {
			Bucket struct {
				Name string `json:"name"`
			} `json:"bucket"`
			Object struct {
				Key string `json:"key"`
			} `json:"object"`
		} `json:"s3"`
	} `json:"Records"`
}

S3Event base structure for an s3 event, to unmarshal a json into it

type SQSEvent

type SQSEvent struct {
	Records []struct {
		MessageID     string `json:"messageId"`
		ReceiptHandle string `json:"receiptHandle"`
		Body          string `json:"body"`
		Attributes    struct {
			ApproximateReceiveCount          string `json:"ApproximateReceiveCount"`
			SentTimestamp                    string `json:"SentTimestamp"`
			SenderID                         string `json:"SenderId"`
			ApproximateFirstReceiveTimestamp string `json:"ApproximateFirstReceiveTimestamp"`
		} `json:"attributes"`
		EventSource    string `json:"eventSource"`
		EventSourceARN string `json:"eventSourceARN"`
		AwsRegion      string `json:"awsRegion"`
	} `json:"Records"`
}

SQSEvent is all the data that gets passed into the lambda from the q IMPROVE: use events.SQSEvent, see summary lambda

Jump to

Keyboard shortcuts

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