github.com/blend/go-sdk@v1.20220411.3/r2/opt_port.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package r2
     9  
    10  import (
    11  	"fmt"
    12  	"net/url"
    13  
    14  	"github.com/blend/go-sdk/ex"
    15  )
    16  
    17  // OptPort sets a custom port for the request url.
    18  func OptPort(port int32) Option {
    19  	return func(r *Request) error {
    20  		if r.Request == nil {
    21  			return ex.New(ErrRequestUnset)
    22  		}
    23  		if r.Request.URL == nil {
    24  			r.Request.URL = &url.URL{}
    25  		}
    26  		r.Request.URL.Host = fmt.Sprintf("%s:%d", r.Request.URL.Hostname(), port)
    27  		return nil
    28  	}
    29  }