gurl

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 3 Imported by: 2 modules, 1 package

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

gurl 包

简介

gurl 包提供了 URL 处理相关的工具函数。

功能特性

  • URL 解析:解析 URL 各部分
  • 参数处理:查询参数的编码解码
  • URL 构建:构建 URL
  • URL 验证:验证 URL 合法性

安装

go get github.com/snail007/gmc/util/url

快速开始

package main

import (
    "fmt"
    "github.com/snail007/gmc/util/url"
)

func main() {
    // 解析 URL
    u, _ := gurl.Parse("https://example.com/path?key=value")
    fmt.Println("Host:", u.Host)
    fmt.Println("Path:", u.Path)
    
    // 构建查询参数
    params := map[string]string{
        "name": "John Doe",
        "age":  "30",
    }
    query := gurl.BuildQuery(params)
    fmt.Println("Query:", query) // name=John+Doe&age=30
    
    // 编码 URL 部分
    encoded := gurl.PathEscape("hello world")
    fmt.Println("Encoded:", encoded) // hello%20world
}

API 参考

  • Parse(rawurl) (*URL, error):解析 URL
  • BuildQuery(params) string:构建查询字符串
  • PathEscape(s) string:转义路径部分
  • QueryEscape(s) string:转义查询参数
  • IsValid(rawurl) bool:验证 URL 是否合法

相关链接

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendQuery

func AppendQuery(URL string, queryData map[string]string) string

func EncodeData

func EncodeData(data map[string]string) string

func GetConcatChar

func GetConcatChar(URL string) string

Types

type Builder

type Builder struct {
	*url.URL
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder() *Builder

func (*Builder) Error

func (s *Builder) Error() error

func (*Builder) HTTP

func (s *Builder) HTTP() *Builder

func (*Builder) HTTPS

func (s *Builder) HTTPS() *Builder

func (*Builder) HolderValuesURL

func (s *Builder) HolderValuesURL(holderValues ...[]string) (urlArr []string)

func (*Builder) Holders

func (s *Builder) Holders(holders ...string) *Builder

func (*Builder) Host

func (s *Builder) Host(host string) *Builder

func (*Builder) HostsURL

func (s *Builder) HostsURL(hosts []string) (urlArr []string)

func (*Builder) Parse

func (s *Builder) Parse(ref string) (b *Builder)

func (*Builder) Path

func (s *Builder) Path(path string) *Builder

func (*Builder) PathsURL

func (s *Builder) PathsURL(paths []string) (urlArr []string)

func (*Builder) Port

func (s *Builder) Port(port string) *Builder

func (*Builder) QueriesURL

func (s *Builder) QueriesURL(queries []map[string]string) (urlArr []string)

func (*Builder) Query

func (s *Builder) Query(data map[string]string) *Builder

func (*Builder) Scheme

func (s *Builder) Scheme(scheme string) *Builder

func (*Builder) SetQuery

func (s *Builder) SetQuery(k, v string) *Builder

func (*Builder) String

func (s *Builder) String() string

Jump to

Keyboard shortcuts

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