feat: add back-end
This commit is contained in:
parent
97b94d4761
commit
4e71c5dacd
|
@ -0,0 +1,12 @@
|
|||
api =
|
||||
{
|
||||
port = 65535;
|
||||
};
|
||||
pq =
|
||||
{
|
||||
db = "database";
|
||||
host = "localhost";
|
||||
port = 5432;
|
||||
secret = "secret";
|
||||
user = "user";
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#include <stdio.h>
|
||||
//for use of exit()
|
||||
#include <stdlib.h>
|
||||
//for use of libconfig
|
||||
#include <libconfig.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
fprintf(stdout,"main() Started...\n");
|
||||
|
||||
/*read command line*/
|
||||
if (argc > 1){
|
||||
printf("main() argv[1]: %s\n", argv[1]);
|
||||
}else{
|
||||
fprintf(stderr, "Usage: %s <path to config file>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
config_t cfg;
|
||||
const char *str;
|
||||
int port;
|
||||
|
||||
/*initialise new and EMPTY config*/
|
||||
config_init(&cfg);
|
||||
|
||||
/* Read the file. If there is an error, report it and exit. */
|
||||
if(! config_read_file(&cfg, argv[1]))
|
||||
{
|
||||
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
|
||||
config_error_line(&cfg), config_error_text(&cfg));
|
||||
/*destroy config, BUT NOT the structure*/
|
||||
config_destroy(&cfg);
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*lookup db string*/
|
||||
if(config_lookup_string(&cfg, "pq.db", &str)){
|
||||
printf("db: %s\n", str);
|
||||
}else{
|
||||
fprintf(stderr, "No 'db' setting in configuration file.\n");
|
||||
}
|
||||
|
||||
/*lookup port int*/
|
||||
if(config_lookup_int(&cfg, "pq.port", &port)){
|
||||
printf("port: %d\n", port);
|
||||
}else{
|
||||
fprintf(stderr, "No 'port' setting in configuration file.\n");
|
||||
}
|
||||
|
||||
config_destroy(&cfg);
|
||||
fprintf(stdout,"main() Done.\n");
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
# Docu
|
||||
#
|
||||
#$@ is the name of the file to be made
|
||||
#$? is the names of the changed dependents
|
||||
#$< the name of the related file that caused the action
|
||||
#$* the prefix shared by target and dependent files
|
||||
#
|
||||
# Others
|
||||
RM = /bin/rm -f
|
||||
#
|
||||
# Source, Executable, Includes, Library Defines
|
||||
EXE = main
|
||||
#
|
||||
# Compiler, Linker Defines
|
||||
CC = /usr/bin/gcc
|
||||
#
|
||||
all: main.o
|
||||
$(CC) main.c -L/usr/lib/x86_64-linux-gnu -lconfig -Wall -o $(EXE)
|
||||
#
|
||||
main.o:
|
||||
$(CC) -c main.c
|
||||
# Clean Up Objects, Exectuables, Dumps out of source directory
|
||||
clean:
|
||||
$(RM) *.o $(EXE) *~
|
|
@ -0,0 +1,23 @@
|
|||
* install dependencies on Debian Bullseye
|
||||
|
||||
```
|
||||
sudo apt install libconfig-dev --no-install-recommends
|
||||
```
|
||||
|
||||
* build
|
||||
|
||||
```
|
||||
make clean all
|
||||
```
|
||||
|
||||
* cleanup
|
||||
|
||||
```
|
||||
make clean
|
||||
```
|
||||
|
||||
* run
|
||||
|
||||
```
|
||||
./main
|
||||
```
|
Loading…
Reference in New Issue