Skip to content

Commit

Permalink
solo request support added
Browse files Browse the repository at this point in the history
  • Loading branch information
yahya077 committed Mar 3, 2024
1 parent a04a07e commit f53a716
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/solo_request/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package main

import (
"fmt"
"github.com/WEG-Technology/room"
)

func main() {
response := room.NewSoloRequest("https://dummyjson.com").Send()

fmt.Println("RequestUri", response.RequestUri())
fmt.Println("RequestHeader", response.RequestHeader().Properties())
fmt.Println("StatusCode", response.StatusCode())
fmt.Println("Header", response.Header().Properties())
fmt.Println("Status", response.Status())
fmt.Println("Ok", response.Ok())
fmt.Println("Dto", response.Dto())
fmt.Println("RequestMethod", response.RequestMethod())
}
35 changes: 35 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,41 @@ type BaseRequest struct {
dto any
}

type ISoloRequest interface {
IRequest
Send() IResponse
}

func NewSoloRequest(baseUrl string, opts ...OptionRequest) ISoloRequest {
r, err := newRequest(opts...)

if err != nil {
panic(err)
}

return &SoloRequest{
BaseRequest: *r.(*BaseRequest),
baseUrl: baseUrl,
}
}

type SoloRequest struct {
baseUrl string
BaseRequest
}

func (r *SoloRequest) Send() IResponse {
c, err := NewConnection(
WithBaseUrl(r.baseUrl),
)

if err != nil {
panic(err)
}

return c.Send(r)
}

func (r *BaseRequest) Cancel() {
if r.cancel != nil {
r.cancel()
Expand Down

0 comments on commit f53a716

Please sign in to comment.