Add template

This commit is contained in:
Tyler Perkins 2023-05-09 21:53:33 -04:00
parent 1ec6df7578
commit 5343cd533e
7 changed files with 81 additions and 0 deletions

0
Dockerfile Normal file
View File

10
src/api/__init__.py Normal file
View File

@ -0,0 +1,10 @@
from flask_restx import Api
from .example import api as example_api
api = Api(
title="API",
version="1.0",
description="API",
)
api.add_namespace(example_api)

16
src/api/example.py Normal file
View File

@ -0,0 +1,16 @@
from flask_restx import Namespace, Resource, fields
from flask_restx import reqparse
from flask import make_response, abort, request, Response
from functools import lru_cache
import requests
import logging
api = Namespace('example', description='Example namespace')
@api.route('/')
@api.doc(description="Example endpoint")
class Example(Resource):
@api.doc('example')
def get(self):
return {'hello': 'world'}

21
src/app.py Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/python
# Entry point
from flask import Flask
from api import api
from config import config, setupLog
import os
import logging
setupLog()
port = config["server.port"]
debug = config["server.debug"]
app = Flask(__name__)
api.init_app(app)
app.run(host='0.0.0.0',
port=config["server.port"],
debug=config["server.debug"])

26
src/config.py Normal file
View File

@ -0,0 +1,26 @@
# Load configuration yaml
import envyaml
import os
import logging
config = envyaml.EnvYAML(os.environ.get('CONFIG_PATH', 'config.yaml'))
def setupLog():
logLevel = config["log.level"]
filename = config["log.filename"]
logFormat = config["log.format"]
level = None
if logLevel == "info":
level =logging.INFO
elif logLevel == "debug":
level = logging.DEBUG
elif logLevel == "warning":
level = logging.WARNING
elif logLevel == "error":
level = logging.ERROR
elif logLevel == "critical":
level = logging.CRITICAL
logging.basicConfig(level=level, filename=filename, format=logFormat)

8
src/config.yaml Normal file
View File

@ -0,0 +1,8 @@
log:
level: "debug"
filename: "application.log"
format: "%(levelname)s : %(message)s"
server:
port: 5000
debug: True

0
src/requirements.txt Normal file
View File