[Plugin] Environment Variables
#1

pawn-env



Provides access to environment variables in Pawn.

Rule III of the Twelve Factor App states:

Store config in the environment

An app’s config is everything that is likely to vary between deploys (staging, production, developer environments, etc). This includes:
  • Resource handles to the database, Memcached, and other backing services
  • Credentials to external services such as Amazon S3 or *******
  • Per-deploy values such as the canonical hostname for the deploy
Apps sometimes store config as constants in the code. This is a violation of twelve-factor, which requires strict separation of config from code. Config varies substantially across deploys, code does not.

(read the rest here)

Installation

Simply install to your project:

Код:
sampctl package install Southclaws/pawn-env
Include in your code and begin using the library:

Код:
#include <env>
Not a sampctl user? See the GitHub for source and binaries.

Usage

This package provides one function GetEnv which stores into dest the environment variable identified by name and returns the length of the result.

For example, this code loads a MySQL password from an environment variable:

Код:
main() {
    new mysqlPassword[128];
    ret = GetEnv("MYSQL_PASSWORD", mysqlPassword);
    if(ret) {
        // use mysqlPassword to connect to DB
    } else {
        print("Environment variable `MYSQL_PASSWORD` not set.");
    }
}
Building

On Windows, to build the standard Windows .dll file: open CMakeLists.txt with Visual Studio 2017+ and develop/build using MSVC tools. To build the Linux build on Windows, run make build-linux and Docker will be used to compile it. On Linux, use CMake: mkdir build && cd build && cmake .. && make.

Testing

To test on Windows or Linux with the need for containers:

Код:
make test-windows
To the Linux build on Windows with a Docker container:

Код:
make test-linux
Reply
#2

What is this used for? Can you explain more?
Reply
#3

good.
Reply
#4

Quote:
Originally Posted by Verc
Посмотреть сообщение
What is this used for? Can you explain more?
If you don't know what it is, you probably don't need it (seems like a running theme with my recent releases...)

Anyway, environment variables are basically standard in all languages. An environment variable is a configuration parameter specific to the machine running the code - not a file, not hard coded and not in a database. Those qualities are important for the reasons explained above.

So the prime use-case for this plugin is to provide a way of configuring gamemodes via the environment not via a file or a database - this is useful if you package your gamemode into a VM image or a Docker image - without environment variables, you'd need to either hard-code configuration into the image or mount a configuration file to the image at runtime, both of these are not really ideal options.
Reply
#5

Nice
Reply
#6

Thank you for another good release
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)