Skip to content

Commit

Permalink
Merge pull request #126 from MarwanGalal746/develop
Browse files Browse the repository at this point in the history
ICAP request identifier
  • Loading branch information
mahnouman authored Nov 13, 2022
2 parents ffe3dfb + f27af68 commit 9e24f38
Show file tree
Hide file tree
Showing 20 changed files with 346 additions and 234 deletions.
20 changes: 14 additions & 6 deletions ADDING-NEW-VENDOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ Assume that the name of the vendor is **abc** and the name of the service **xyz*
- Create a struct named **Abc** with the required attributes of any service to this vendor.

- **Mandatory fields**:
- **xICAPMetadata**: It's the id of every **ICAP** request sent to **ICAPeg**.
- **httpMsg**: It's an instance from [**HttpMsg**](http-message/httpMessage.go) struct which groups two field (**HTTP request** and **HTTP response**). The developer can process the **HTTP message(request or response)** through this instance.
- **serviceName**: It's the service name value.
- **methodName**: It's method name value.

- **Optional fields**:
- **generalFunc**: It's an instance from [**GeneralFunc**](service/services-utilities/general-functions/general-functions.go) struct which has a lot of function that may help the developer in processing **HTTP messages**.

```go
type Abc struct {
//mandatory
xICAPMetadata string
httpMsg *utils.HttpMsg
serviceName string
methodName string
Expand Down Expand Up @@ -137,9 +140,10 @@ Assume that the name of the vendor is **abc** and the name of the service **xyz*
It extracts service configuration from **abcConfig** variable.

```go
func NewAbcService(serviceName, methodName string, httpMsg *utils.HttpMsg) *abc {
func NewAbcService(serviceName, methodName string, httpMsg *utils.HttpMsg, xICAPMetadata string) *abc {
return &Abc{
//mandatory
xICAPMetadata: xICAPMetadata, //the id of the ICAP request
httpMsg: httpMsg,
serviceName: serviceName,
methodName: methodName,
Expand All @@ -166,13 +170,17 @@ Assume that the name of the vendor is **abc** and the name of the service **xyz*

```go
//Processing is a func used for to processing the http message
func (reciever *Abc) Processing() (int, interface{}, map[string]string, map[string]interface{}, map[string]interface{}, map[string]interface{}) {
func (reciever *Abc) Processing(partial bool) (int, interface{}, map[string]string, map[string]interface{}, map[string]interface{}, map[string]interface{}) {
// your implementation
}
```

The values **Processing() function** returns:
The values **Processing() function** paramaters:

- **partial bool**: Boolean variable refer to wether the content is partial content or complete content.

The values **Processing() function** returns:

- **int**: ICAP response status code.
- **interface{}**: HTTP message after processing, It can be HTTP request if the ICAP request methos is REQMOD or HTTP response if the ICAP request methos is RESPMOD.
- **map[string]string**: map contains any headers related to the vendor and wanted to be added to ICAP response.
Expand All @@ -195,12 +203,12 @@ const (
- Add a case in the switch case in **GetService** function by the new vendor

```go
func GetService(vendor, serviceName, methodName string, httpMsg *utils.HttpMsg) Service {
func GetService(vendor, serviceName, methodName string, httpMsg *utils.HttpMsg, xICAPMetadata string) Service {
switch vendor {
case VendorEcho:
return echo.NewEchoService(serviceName, methodName, httpMsg)
return echo.NewEchoService(serviceName, methodName, httpMsg, xICAPMetadata)
case VendorABC:
return abc.NewAbcService(serviceName, methodName, httpMsg)
return abc.NewAbcService(serviceName, methodName, httpMsg, xICAPMetadata)
}
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions DEVELOPER-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@
```go
type GeneralFunc struct {
httpMsg *http_message.HttpMsg
xICAPMetadata string
}
```

So the developer can add [**GeneralFunc**](./service/services-utilities/general-functions/general-functions.go) field in the struct of the service which he implements, like [**Echo service**](service/services/echo/config.go), a field from type [**GeneralFunc**](./service/services-utilities/general-functions/general-functions.go) is defined as the last field in [**Echo service**](service/services/echo/config.go) struct as shown below.

```go
type Echo struct {
xICAPMetadata string
httpMsg *http_message.HttpMsg
elapsed time.Duration
serviceName string
Expand Down Expand Up @@ -100,6 +102,8 @@ type HttpMsg struct {

[**HttpMsg**](consts/httpMessage.go) field in [**GeneralFunc**](./service/services-utilities/general-functions/general-functions.go) struct facilitates [**GeneralFunc**](./service/services-utilities/general-functions/general-functions.go) dealing with HTTP request and response.

**xICAPMetadata** is a string value of the ID of **ICAP** request sent to **ICAPeg**.

## Functions

- ### **CopyingFileToTheBuffer**
Expand Down
5 changes: 5 additions & 0 deletions WRITE-LOGS-FOR-VENDOR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## **How to write logs for a vendor?**

```go
logging.Logger.Info(utils.PrepareLogMsg(<the X-ICAP-Metadata of the service>, <The message you want to log>))
```
Loading

0 comments on commit 9e24f38

Please sign in to comment.