Responsabilities:
cmd/nethegateapi/main.go starts the application/service
internal/openAPIHandlers : These are the handlers generated by OpenAPI. They route requests to the service (eg createNewUser, )
internal/nethGateAPI: This is the core of the service. It is responsible for handling the requests, for example generating a new API key for users, syncing this with Kong, and storing the users data in a local DB
internal/kongAdminAPI: we need this to sync our users data with Kong (ie integrate with Kong Admin API)
internal/juno: this is just to make RPC calls to Juno
internal/db: this is to store the user data in a local data base persistently
Structure:
internal/openAPIHandlers imports internal/nethGateAPI
internal/nethGateAPI imports internal/kongAdminAPI, internal/juno, internal/db
Other notes:
Handling New Consumers:
- Registration Through Your Handlers : When a new user (consumer) registers via your API, your handler for user registration will process this.
- API Key Generation : As part of this registration process, your system will generate an API key for the new user.
- Sync with Kong : You then use Kong's Admin API to register this user as a consumer in Kong and associate the generated API key with them. This step is crucial for Kong to recognize and validate the API key in future requests.
- Save API Key in Database : Store the API key and any other relevant user information in your database.
- Return API Key to User : Respond to the user with their API key, which they will use for subsequent requests.
Handling Requests from Existing Consumers:
- API Requests with API Key : Existing users send requests to your API endpoints exposed by Kong, including their API key for authentication.
- Kong Gateway Filters Traffic : Kong processes these requests first, validating the API keys and applying any other configured filters like rate limiting.
- Routing to Your Application : If the request is valid, Kong routes it to your application.
- Application Processes Request : Your application then processes the request. Since it's about interacting with a blockchain client, this step involves sending transactions to the blockchain, querying data, etc.
- Responding to User : After processing, your application sends the response back through Kong to the user.