Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from JesseCoretta/v1.0.1
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
JesseCoretta committed Mar 2, 2024
2 parents 8223e29 + 593335a commit 44be0e9
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 86 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '26 2 * * 1'

jobs:
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
83 changes: 80 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,83 @@
# go-stackage

[![Go Report Card](https://goreportcard.com/badge/github.com/JesseCoretta/go-stackage)](https://goreportcard.com/report/github.com/JesseCoretta/go-stackage) [![codecov](https://codecov.io/gh/JesseCoretta/go-stackage/branch/v1-dev/graph/badge.svg?token=RLW4DHLKQP)](https://codecov.io/gh/JesseCoretta/go-stackage/tree/v1-dev/) [![Go Reference](https://pkg.go.dev/badge/github.com/JesseCoretta/go-stackage.svg)](https://pkg.go.dev/github.com/JesseCoretta/go-stackage) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/JesseCoretta/go-stackage/blob/main/LICENSE) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/JesseCoretta/go-stackage/issues) [![Experimental](https://img.shields.io/badge/experimental-blue?logoColor=blue&label=%F0%9F%A7%AA%20%F0%9F%94%AC&labelColor=blue&color=gray)](https://github.com/JesseCoretta/JesseCoretta/blob/main/EXPERIMENTAL.md) [![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/jessecoretta/go-aci/go.yml?event=push)](https://github.com/JesseCoretta/go-stackage/actions/workflows/go.yml)
[![Author](https://img.shields.io/badge/author-Jesse_Coretta-darkred?label=%F0%9F%94%BA&labelColor=indigo&color=maroon)](https://www.linkedin.com/in/jessecoretta/) [![Help Animals](https://img.shields.io/badge/donations-yellow?label=%F0%9F%98%BA&labelColor=Yellow)](https://github.com/JesseCoretta/JesseCoretta/blob/main/DONATIONS.md)
[![Go Report Card](https://goreportcard.com/badge/github.com/JesseCoretta/go-stackage)](https://goreportcard.com/report/github.com/JesseCoretta/go-stackage) [![Go Reference](https://pkg.go.dev/badge/github.com/JesseCoretta/go-stackage.svg)](https://pkg.go.dev/github.com/JesseCoretta/go-stackage) [![CodeQL](https://github.com/JesseCoretta/go-stackage/workflows/CodeQL/badge.svg)](https://github.com/JesseCoretta/go-stackage/actions/workflows/github-code-scanning/codeql) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/JesseCoretta/go-stackage/blob/main/LICENSE) [![codecov](https://codecov.io/gh/JesseCoretta/go-stackage/graph/badge.svg?token=RLW4DHLKQP)](https://codecov.io/gh/JesseCoretta/go-stackage) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/JesseCoretta/go-stackage/issues) [![Experimental](https://img.shields.io/badge/experimental-blue?logoColor=blue&label=%F0%9F%A7%AA%20%F0%9F%94%AC&labelColor=blue&color=gray)](https://github.com/JesseCoretta/JesseCoretta/blob/main/EXPERIMENTAL.md) [![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/jessecoretta/go-stackage/go.yml?event=push)](https://github.com/JesseCoretta/go-stackage/actions/workflows/go.yml) [![Author](https://img.shields.io/badge/author-Jesse_Coretta-darkred?label=%F0%9F%94%BA&labelColor=indigo&color=maroon)](mailto:jesse.coretta@icloud.com) [![GitHub release (with filter)](https://img.shields.io/github/v/release/JesseCoretta/go-stackage)](https://github.com/JesseCoretta/go-stackage/releases) [![Help Animals](https://img.shields.io/badge/help_animals-gray?label=%F0%9F%90%BE%20%F0%9F%98%BC%20%F0%9F%90%B6&labelColor=yellow)](https://github.com/JesseCoretta/JesseCoretta/blob/main/DONATIONS.md)

![stacks03](https://github.com/JesseCoretta/go-stackage/assets/74126726/ec6429ac-d698-413b-8c1c-0ac8dc1e301c)

## Summary

The stackage package implements flexible Stack and Condition types with many useful features. It can be used to create object-based Boolean statements, abstract mathematical constructs, simple lists and much more: the possibilities are endless!

## Mission

The main goal of this package is provide an extremely reliable and accommodating stack/condition solution that is suitable for use in virtually any conceivable Go-based scenario in which objects of these types are needed. While extremely extensible and flexible, it should always be possible to use this package with no need for additional (non main) code while operating in extremely simple scenarios.

## Features

- Stack instances are either LIFO (stack based, default) or FIFO (queue based)
- FIFO is First-In/First-Out (like a line at your favorite deli: first come, first serve)
- LIFO is Last-In/First-Out (like those plate-stacking apparatuses found in restaurant kitchens, in which the first plate inserted shall be the last plate removed)
- Flexible Stack configuration controls, allowing custom stringer presentation, push controls and validity-checking policies to be imposed
- Recursive design - Stacks can reside in Stacks. Conditions can reside in Stacks. Conditions can contain other Stacks. Whatever!
- Eligible values are easily navigated using the Stack.Traverse method using an ordered sequence of indices, or slice index numbers
- Conversely, recursion capabilities can also be easily disabled per instance!
- Observable - flexible logging facilities, using the [log](https://pkg.go.dev/log) package are available globally, or on a per-instance basis
- Interrogable - Stacks and Conditions extend many interrogation features, allowing the many facets and "states" of an instance to be queried simply
- Resilient - Stack writeability can be toggled easily, allowing safe (albeit naïve) read-only operation without the need for mutexing
- Fluent-style - Types which offer methods for cumulative configuration are written in fluent-form, allowing certain commands to be optionally "chained" together
- Extensible
- Logical operator framework allows custom operators to be added for specialized expressions, instead of the package-provided ComparisonOperator constants
- Users can add their own Evaluator function to perform computational tasks, value interrogation, matching procedures ... pretty much anything you could imagine
- Stack instances are (independently) MuTeX capable, thanks to the [sync](https://pkg.go.dev/sync) package
- Recursive locking mechanisms are NOT supported due to my aversion to insanity
- Adopters may create a type alias of the Condition and/or Stack types
- See the [Type Aliasing](#type-aliasing) section below
- Fast, reliable, useful, albeit very niche

## Status

Although fairly well-tested, this package is in its early stages and is undergoing active development. It should only be used in production environments while under heavy scrutiny and with great care.

## License

The stackage package, from [`go-stackage`](https://github.com/JesseCoretta/go-stackage), is released under the terms of the MIT license. See the [`LICENSE`](https://github.com/JesseCoretta/go-stackage/blob/main/LICENSE) file in the repository root, or click the License badge above, for complete details.

## Type Aliasing

When needed, users may opt to create their own derivative alias types of either the Stack or Condition types for more customized use in their application.

The caveat, naturally, is that users will be expected to wrap all of the package-provided methods (e.g.: `String`, `Push`, `Pop`, etc) they intend to use.

However, the upside is that the user may now write (extend) wholly _new_ methods that are unique to their own application, and _without_ having to resort to potentially awkward measures, such as embedding.

To create a derivative type based on the Stack type, simply do something similar to the following example in your code:

```
type MyStack stackage.Stack
// Here we extend a wholly new function. The input and output signatures
// are entirely defined at the discretion of the author and are shown in
// "pseudo code context" here.
func (r MyStack) NewMethodName([input signature]) [<output signature>] {
// your custom code, do whatever!
}
// Here we wrap a pre-existing package-provided function, String, that
// one would probably intend to use.
//
// To run the actual String method, we need to first CAST the custom
// type (r, MyStack) to a bonafide stackage.Stack instance as shown
// here. Unlike the above example, this is NOT "pseudo code" and will
// compile just fine.
//
// Repeat as needed for other methods that may be used.
func (r MyStack) String() string {
// return the result from a "TYPE CAST -> EXEC" call
return stackage.Stack(r).String()
}
```

The procedure would be identical for a Condition alias -- just change the name and the derived stackage type from the first example line and modify as desired.

If you'd like to see a more complex working example of this concept in the wild, have a look at the [`go-aci`](https://github.com/JesseCoretta/go-aci) package, which makes **heavy use** of derivative stackage types.

Package stackage implements a flexible Stack type with useful features.
26 changes: 0 additions & 26 deletions cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ package stackage
cond.go contains Condition-related methods and functions.
*/

import (
"log"
)

/*
Condition describes a single evaluative statement, i.e.:
Expand Down Expand Up @@ -338,24 +334,6 @@ func (r Condition) SetLogger(logger any) Condition {
return r
}

/*
Logger returns the *log.Logger instance. This can be used for quick
access to the log.Logger type's methods in a manner such as:
r.Logger().Fatalf("We died")
It is not recommended to modify the return instance for the purpose
of disabling logging outright (see Stack.SetLogger method as well
as the SetDefaultConditionLogger package-level function for ways of
doing this easily).
*/
func (r Condition) Logger() (l *log.Logger) {
if r.IsInit() {
l = r.condition.logger()
}
return
}

/*
Err returns the error residing within the receiver, or nil
if no error condition has been declared.
Expand Down Expand Up @@ -911,10 +889,6 @@ func (r *condition) setLogger(logger any) {
r.cfg.log.setLogger(logger)
}

func (r condition) logger() *log.Logger {
return r.cfg.log.logger()
}

func (r *condition) toggleOpt(cf cfgFlag) {
r.cfg.toggleOpt(cf)
}
Expand Down
22 changes: 1 addition & 21 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
/*
Package stackage implements a flexible stack type optimized for use in creating and presenting conditional Boolean statements, abstract mathematical constructs, LDAP filter abstractions or simple lists.
# Features
- Flexible Stack configuration controls, allowing custom presentation, push and validity policies to be executed (instead of default behavior) through the use of closure signature functions
- Recursive design - Stacks can reside in Stacks. Conditions can reside in Stacks. Conditions can contain other Stacks. Whatever.
- Traversible - Recursive values are easily navigated using the Stack.Traverse method
- Fluent-style - types which offer methods for cumulative configuration are written in fluent-form, allowing certain commands to be optionally "chained" together
- Extensible logical operator framework, allowing custom operators to be added for specialized expressions instead of the package-provided ComparisonOperator constants
- MuTeX capable for each Stack instance independent of its parent or child (no recursive locking mechanisms)
- Adopters may wish to create a type alias of the Condition and/or Stack types; this is particularly easy, and will not impact normal operations when dealing with nested instances of derivative types
- Assertion capabilities; go beyond merely crafting the string representation of a formula -- add an Evaluator function to conduct an interrogation of a value, matching procedures, and more!
- Fast, reliable, useful
# Status
This package is in its early stages, and is undergoing active development. It should NOT be used in any production capacity at this time.
# License
The stackage (go-stackage) package, from http://github.com/JesseCoretta/go-stackage, is available under the terms of the MIT license. For further details, see the LICENSE file within the aforementioned repository.
Package stackage implements a flexible stack type optimized for use in creating and presenting conditional Boolean statements, abstract mathematical constructs, or simple lists: the possibilities are endless!
*/
package stackage
46 changes: 46 additions & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,52 @@ func getLogID(elem string) (id string) {
return
}

/*
Logger returns the *log.Logger instance. This can be used for quick
access to the log.Logger type's methods in a manner such as:
r.Logger().Fatalf("We died")
It is not recommended to modify the return instance for the purpose
of disabling logging outright (see Stack.SetLogger method as well
as the SetDefaultStackLogger package-level function for ways of
doing this easily).
*/
func (r Stack) Logger() (l *log.Logger) {
if r.IsInit() {
l = r.stack.logger()
}
return

}

func (r *stack) logger() *log.Logger {
cfg, _ := r.config()
return cfg.log.logger()
}

/*
Logger returns the *log.Logger instance. This can be used for quick
access to the log.Logger type's methods in a manner such as:
r.Logger().Fatalf("We died")
It is not recommended to modify the return instance for the purpose
of disabling logging outright (see Stack.SetLogger method as well
as the SetDefaultConditionLogger package-level function for ways of
doing this easily).
*/
func (r Condition) Logger() (l *log.Logger) {
if r.IsInit() {
l = r.condition.logger()
}
return
}

func (r condition) logger() *log.Logger {
return r.cfg.log.logger()
}

func init() {
stderr = log.New(os.Stderr, ``, 0)
stdout = log.New(os.Stdout, ``, 0)
Expand Down

0 comments on commit 44be0e9

Please sign in to comment.