forked from alibaba/funcraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85a0a3c
commit d1f2d67
Showing
181 changed files
with
32,354 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "event-custom-cpp", | ||
"description": "cpp template for Custom Runtime", | ||
"vars": { | ||
"service": "{{ projectName }}" | ||
}, | ||
"copyOnlyPaths": [ "libpistache.a" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
build-img: | ||
docker build -t fc-cpp-runtime -f build-image/Dockerfile build-image | ||
|
||
build: build-img | ||
docker run --rm -it -v $$(pwd):/tmp fc-cpp-runtime bash -c "cd /tmp && ./build.sh" | ||
|
||
deploy: build | ||
fun deploy -y | ||
|
||
.PHONY: deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## CPP template for Custom Runtime | ||
|
||
### Deploy | ||
|
||
```bash | ||
$ event-custom-cpp make deploy | ||
``` | ||
### Invoke | ||
```bash | ||
$ event-custom-cpp fun invoke -e "HelloCustomCpp" | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
78 changes: 78 additions & 0 deletions
78
templates/event-custom-cpp/{{ projectName }}/include/handler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#pragma once | ||
#include <pistache/net.h> | ||
#include <pistache/http.h> | ||
#include <pistache/peer.h> | ||
#include <pistache/http_headers.h> | ||
#include <pistache/cookie.h> | ||
#include <pistache/endpoint.h> | ||
#include <pistache/common.h> | ||
#include <queue> | ||
#include <map> | ||
#include <chrono> | ||
#include "fc_context.h" | ||
#include "logging.h" | ||
namespace Aliyun { | ||
namespace FC { | ||
class FcBaseHandler | ||
{ | ||
public: | ||
FcBaseHandler() :mLogger(nullptr) {} | ||
void SetLogger(Logger* logger) {mLogger = logger;} | ||
virtual void OnInvoke(const std::string& payload, const FcContext& context, std::string& response) = 0; | ||
virtual void OnInitialize(const FcContext& context) = 0; | ||
|
||
private: | ||
Logger* mLogger; | ||
}; | ||
|
||
class FcHttpBaseHandler | ||
{ | ||
public: | ||
FcHttpBaseHandler() :mLogger(nullptr) {} | ||
void SetLogger(Logger* logger) {mLogger = logger;} | ||
virtual void OnInvoke(const FcContext& context, const Pistache::Http::Request& req, | ||
Pistache::Http::ResponseWriter& response) = 0; | ||
virtual void OnInitialize(const FcContext& context) = 0; | ||
|
||
private: | ||
Logger* mLogger; | ||
}; | ||
|
||
class CustomRuntimeHandler : public Pistache::Http::Handler { | ||
|
||
HTTP_PROTOTYPE(CustomRuntimeHandler) | ||
|
||
public: | ||
void onRequest( | ||
const Pistache::Http::Request& req, | ||
Pistache::Http::ResponseWriter response) override; | ||
|
||
static FcBaseHandler* normalHandler; | ||
}; | ||
|
||
#define CUSTOM_HEADER2(header_name, header_real_name) \ | ||
class header_name : public Pistache::Http::Header::Header { \ | ||
public: \ | ||
NAME(header_real_name) \ | ||
\ | ||
header_name() = default; \ | ||
\ | ||
explicit header_name(const char* value) \ | ||
: value_{value} {} \ | ||
\ | ||
explicit header_name(std::string value) \ | ||
: value_(std::move(value)) {} \ | ||
\ | ||
void parseRaw(const char *str, size_t len) final \ | ||
{ value_ = { str, len };} \ | ||
\ | ||
void write(std::ostream& os) const final \ | ||
{ os << value_; }; \ | ||
\ | ||
std::string val() const { return value_; }; \ | ||
\ | ||
private: \ | ||
std::string value_; \ | ||
}; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
templates/event-custom-cpp/{{ projectName }}/sample/include/echo_handler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
#include "handler.h" | ||
namespace Aliyun { | ||
namespace FC { | ||
namespace Handlers { | ||
class EchoHandler : public FcBaseHandler | ||
{ | ||
public: | ||
void OnInvoke(const std::string& payload, const FcContext& context, std::string& response) override; | ||
void OnInitialize(const FcContext& context) override; | ||
private: | ||
static std::string mInitHandler; | ||
}; | ||
}}} |
18 changes: 18 additions & 0 deletions
18
templates/event-custom-cpp/{{ projectName }}/sample/src/handlers/echo_handler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "echo_handler.h" | ||
using namespace std; | ||
using namespace Pistache; | ||
|
||
namespace Aliyun { | ||
namespace FC { | ||
namespace Handlers { | ||
std::string EchoHandler::mInitHandler; | ||
void EchoHandler::OnInvoke(const string& payload, const FcContext& context, string& response) | ||
{ | ||
response = EchoHandler::mInitHandler + payload; | ||
} | ||
|
||
void EchoHandler::OnInitialize(const FcContext& context) | ||
{ | ||
EchoHandler::mInitHandler = context.initializer; | ||
} | ||
}}} |
9 changes: 9 additions & 0 deletions
9
templates/event-custom-cpp/{{ projectName }}/sample/src/register_handler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* register invoke and init handler. | ||
*/ | ||
#include "echo_handler.h" | ||
#include "entrypoint.h" | ||
using namespace Aliyun::FC::Handlers; | ||
void SetInvokeAndInitHander() | ||
{ | ||
CustomRuntimeHandler::normalHandler = new EchoHandler(); | ||
} |
Oops, something went wrong.