url

package module
v0.0.0-...-6cb6d12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

xk6-url

This is a k6 extension using the xk6 system.

❗ This is a proof of concept, isn't supported by the k6 team, and may break in the future. USE AT YOUR OWN RISK!

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Install xk6:
$ go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the binary:
$ xk6 build --with github.com/dgzlopes/xk6-url@latest

Example

import url from 'k6/x/url';

export default function () {
  var parsed = url.parse("user.local:8000/path")
  console.log(`Scheme: ${parsed.scheme} `)
  console.log(`Host: ${parsed.host}`)
  console.log(`Path: ${parsed.path}`)

  var normalized = url.normalize("localhost:80///x///y/z/../././index.html?b=y&a=x#t=20")
  console.log(normalized)

  var split = url.splitHostPort("localhost:80")
  console.log(`Host: ${split.host}`)
  console.log(`Port: ${split.port}`)

  console.log(url.resolve("example.com"))
}

Result output:

$ ./k6 run script.js

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: ../example.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] Scheme: http                                  source=console
INFO[0000] Host: user.local:8000                         source=console
INFO[0000] Path: /path                                   source=console
INFO[0000] http://localhost/x/y/index.html?a=x&b=y#t=20  source=console
INFO[0000] Host: localhost                               source=console
INFO[0000] Port: 80                                      source=console
INFO[0000] 93.184.216.34                                 source=console

running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU

    data_received........: 0 B 0 B/s
    data_sent............: 0 B 0 B/s
    iteration_duration...: avg=906.98µs min=906.98µs med=906.98µs max=906.98µs p(90)=906.98µs p(95)=906.98µs
    iterations...........: 1   44.168084/s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReportError

func ReportError(err error, msg string)

ReportError is a handy function to show errors

Types

type SPLIT

type SPLIT struct {
	Host string
	Port string
}

SPLIT is used by SplitHostPort

type URL

type URL struct{}

URL is the k6 url extension.

func (*URL) Normalize

func (*URL) Normalize(url string) string

Normalize returns normalized URL.

func (*URL) Parse

func (*URL) Parse(url string) *url.URL

Parse parses raw URL string into the net/url URL struct.

func (*URL) Resolve

func (*URL) Resolve(url string) *net.IPAddr

Resolve resolves the URL host to its IP address.

func (*URL) SplitHostPort

func (*URL) SplitHostPort(url string) *SPLIT

SplitHostPort splits network address of the form "host:port" into host and port.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址