github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/applicationgatewayprivatelinkresources_server.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // Licensed under the MIT License. See License.txt in the project root for license information. 6 // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 package fake 10 11 import ( 12 "errors" 13 "fmt" 14 azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" 18 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6" 19 "net/http" 20 "net/url" 21 "regexp" 22 ) 23 24 // ApplicationGatewayPrivateLinkResourcesServer is a fake server for instances of the armnetwork.ApplicationGatewayPrivateLinkResourcesClient type. 25 type ApplicationGatewayPrivateLinkResourcesServer struct { 26 // NewListPager is the fake for method ApplicationGatewayPrivateLinkResourcesClient.NewListPager 27 // HTTP status codes to indicate success: http.StatusOK 28 NewListPager func(resourceGroupName string, applicationGatewayName string, options *armnetwork.ApplicationGatewayPrivateLinkResourcesClientListOptions) (resp azfake.PagerResponder[armnetwork.ApplicationGatewayPrivateLinkResourcesClientListResponse]) 29 } 30 31 // NewApplicationGatewayPrivateLinkResourcesServerTransport creates a new instance of ApplicationGatewayPrivateLinkResourcesServerTransport with the provided implementation. 32 // The returned ApplicationGatewayPrivateLinkResourcesServerTransport instance is connected to an instance of armnetwork.ApplicationGatewayPrivateLinkResourcesClient via the 33 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 34 func NewApplicationGatewayPrivateLinkResourcesServerTransport(srv *ApplicationGatewayPrivateLinkResourcesServer) *ApplicationGatewayPrivateLinkResourcesServerTransport { 35 return &ApplicationGatewayPrivateLinkResourcesServerTransport{ 36 srv: srv, 37 newListPager: newTracker[azfake.PagerResponder[armnetwork.ApplicationGatewayPrivateLinkResourcesClientListResponse]](), 38 } 39 } 40 41 // ApplicationGatewayPrivateLinkResourcesServerTransport connects instances of armnetwork.ApplicationGatewayPrivateLinkResourcesClient to instances of ApplicationGatewayPrivateLinkResourcesServer. 42 // Don't use this type directly, use NewApplicationGatewayPrivateLinkResourcesServerTransport instead. 43 type ApplicationGatewayPrivateLinkResourcesServerTransport struct { 44 srv *ApplicationGatewayPrivateLinkResourcesServer 45 newListPager *tracker[azfake.PagerResponder[armnetwork.ApplicationGatewayPrivateLinkResourcesClientListResponse]] 46 } 47 48 // Do implements the policy.Transporter interface for ApplicationGatewayPrivateLinkResourcesServerTransport. 49 func (a *ApplicationGatewayPrivateLinkResourcesServerTransport) Do(req *http.Request) (*http.Response, error) { 50 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 51 method, ok := rawMethod.(string) 52 if !ok { 53 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 54 } 55 56 var resp *http.Response 57 var err error 58 59 switch method { 60 case "ApplicationGatewayPrivateLinkResourcesClient.NewListPager": 61 resp, err = a.dispatchNewListPager(req) 62 default: 63 err = fmt.Errorf("unhandled API %s", method) 64 } 65 66 if err != nil { 67 return nil, err 68 } 69 70 return resp, nil 71 } 72 73 func (a *ApplicationGatewayPrivateLinkResourcesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { 74 if a.srv.NewListPager == nil { 75 return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} 76 } 77 newListPager := a.newListPager.get(req) 78 if newListPager == nil { 79 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/applicationGateways/(?P<applicationGatewayName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/privateLinkResources` 80 regex := regexp.MustCompile(regexStr) 81 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 82 if matches == nil || len(matches) < 3 { 83 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 84 } 85 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 86 if err != nil { 87 return nil, err 88 } 89 applicationGatewayNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationGatewayName")]) 90 if err != nil { 91 return nil, err 92 } 93 resp := a.srv.NewListPager(resourceGroupNameParam, applicationGatewayNameParam, nil) 94 newListPager = &resp 95 a.newListPager.add(req, newListPager) 96 server.PagerResponderInjectNextLinks(newListPager, req, func(page *armnetwork.ApplicationGatewayPrivateLinkResourcesClientListResponse, createLink func() string) { 97 page.NextLink = to.Ptr(createLink()) 98 }) 99 } 100 resp, err := server.PagerResponderNext(newListPager, req) 101 if err != nil { 102 return nil, err 103 } 104 if !contains([]int{http.StatusOK}, resp.StatusCode) { 105 a.newListPager.remove(req) 106 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} 107 } 108 if !server.PagerResponderMore(newListPager) { 109 a.newListPager.remove(req) 110 } 111 return resp, nil 112 }