Partial port of Python difflib package to Go

Related tags

Network go-difflib
Overview

go-difflib

THIS PACKAGE IS NO LONGER MAINTAINED.

At this point, I have no longer the time nor the interest to work on go-difflib. I apologize for the inconvenience.

GoDoc

Go-difflib is a partial port of python 3 difflib package. Its main goal was to make unified and context diff available in pure Go, mostly for testing purposes.

The following class and functions (and related tests) have be ported:

  • SequenceMatcher
  • unified_diff()
  • context_diff()

Installation

$ go get github.com/pmezard/go-difflib/difflib

Quick Start

Diffs are configured with Unified (or ContextDiff) structures, and can be output to an io.Writer or returned as a string.

diff := difflib.UnifiedDiff{
    A:        difflib.SplitLines("foo\nbar\n"),
    B:        difflib.SplitLines("foo\nbaz\n"),
    FromFile: "Original",
    ToFile:   "Current",
    Context:  3,
}
text, _ := difflib.GetUnifiedDiffString(diff)
fmt.Printf(text)

would output:

--- Original
+++ Current
@@ -1,3 +1,3 @@
 foo
-bar
+baz
Comments
  • Rework line ending handling

    Rework line ending handling

    Hello & thank for a nice lib! I needed to repurpose it a little hence the pull request. These changes will break current usage, because it changes how lines are stored It was changed to render line endings with diff.Eol so it could display properly on Windows, and now simply returns a []string with the diff, without line endings encoded.

    The second commit is just some tweaks that gometalinter mentioned.

    opened by martinlindhe 2
  • Skip file headers if FromFile/ToFile are empty

    Skip file headers if FromFile/ToFile are empty

    Hiya, thanks for writing this library, saved me a lot of work. :)

    I'm using it in a context where I need to create the headers myself since there is more metadata necessary than difflib supports (or should support, like modes and such), so I'd like to be able to disable the filename headers which I'll be handling myself as well. Fairly simple change, let me know if you require tests for it.

    opened by shazow 2
  • Implement a []byte-base API in a

    Implement a []byte-base API in a "bytes" subpackage

    Even with a lot of improvements compared to the current master, it still uses around 1.5x the time of the string-based implementation and API, so put it in a bytes subpackage and restore the original v1.1.2 string implementation in the toplevel package. When/if the []byte API improves enough (or an interface{}-based one), this decision might be revisited to make the string API a user of the bytes subpackage.

    opened by FrnchFrgg 1
  • fix WriteUnifiedDiff/WriteContextDiff fmt.Sprintf error

    fix WriteUnifiedDiff/WriteContextDiff fmt.Sprintf error

    The WriteUnifiedDiff and WriteContextDiff func use fmt.Sprint to output, if diff string has %s ... flag to error output.

    fmt.Printf("%s,%T",a,b) => fmt.Printf("%!s(MISSING),%!T(MISSING)\n", obj, obj)

    opened by visualfc 1
  • difflib: optimize SplitLines

    difflib: optimize SplitLines

    Use strings.SplitAfter to avoid an allocation and copy per line.

    benchmark                    old ns/op     new ns/op     delta
    BenchmarkSplitLines100       25744         7168          -72.16%
    BenchmarkSplitLines10000     2227947       369944        -83.40%
    
    benchmark                    old allocs     new allocs     delta
    BenchmarkSplitLines100       109            1              -99.08%
    BenchmarkSplitLines10000     10021          1              -99.99%
    
    benchmark                    old bytes     new bytes     delta
    BenchmarkSplitLines100       6144          1664          -72.92%
    BenchmarkSplitLines10000     1030960       163840        -84.11%
    
    opened by rdwilliamson 1
  • Proposing change to license so Github will match.

    Proposing change to license so Github will match.

    I'm trying to format the text so that github will recognize that this is the BSD-3-Clause license text. It wasn't able to do that before. I'm hoping this will work.

    opened by aijamalnk 0
  • Fix function comments based on best practices from Effective Go

    Fix function comments based on best practices from Effective Go

    Hi, we updated some exported function comments based on best practices from Effective Go. It’s admittedly a relatively minor fix up. Does this help you?

    opened by CodeLingoTeam 0
Owner
Patrick Mézard
Patrick Mézard
Port-proxy - Temporary expose port for remote connections

Port proxy util Temporary expose port for remote connections. E.g. database/wind

Vadym S 1 Jan 27, 2022
Python's webbrowser in Go. Simple API for opening web pages on your default browser.

webbrowser webbrowser provides a simple API for opening web pages on your default browser. It's inspired on Python's webbrowser package but lacks some

Carlos Cobo 181 Oct 31, 2022
Fastest python library for making asynchronous group requests.

FGrequests: Fastest Asynchronous Group Requests Installation Install using pip: pip install fgrequests Documentation Pretty easy to use. import fgrequ

Farid Chowdhury 14 Nov 22, 2022
A python comtrade load library accelerated by go

Comtrade-GRPC Code for python used is mainly from dparrini/python-comtrade. Just

Bo 1 Dec 27, 2021
grobotstxt is a native Go port of Google's robots.txt parser and matcher library.

grobotstxt grobotstxt is a native Go port of Google's robots.txt parser and matcher C++ library. Direct function-for-function conversion/port Preserve

Jim Smart 86 Dec 4, 2022
Simple HTTP tunnel using SSH remote port forwarding

Simple HTTP tunnel using SSH remote port forwarding

Skye L. 23 Nov 18, 2022
A fast port forwarding or reverse forwarding tool over HTTP1.0/HTTP1.1

gogw What's gogw ? gogw is a port forwarding/reverse forwarding tool over HTTP implements by golang. port forwarding/port reverse forwarding support T

xitongsys 47 Sep 27, 2022
rconn is a multiplatform program for creating generic reverse connections. Lets you consume services that are behind firewall or NAT without opening ports or port-forwarding.

rconn (r[everse] conn[ection]) is a multiplatform program for creating reverse connections. It lets you consume services that are behind NAT and/or fi

Hikmat Jafarli 306 Nov 22, 2022
Capture packet request/response pairs for a port and/or IP to aid in Network protocol based Nuclei Templates creation.

network-fingerprint Capture packet request/response pairs for a port and/or IP to aid in Network protocol based Nuclei Templates creation. Resources I

ProjectDiscovery 45 Nov 15, 2022
A simple port scanner written in go

Scan27 A simple port scanner written in go Features: V1 it Scans the given Ip or Host name for open ports Usage ./scan27 Enter IP address or Host name

null 5 Jul 23, 2022
Yet another TCP Port Scanner, but lightning faster.

Fast TCP Port Scanner A highly concurrent TCP port scanner. Run Tests with Code Coverage (Linux) go test -cover Compile (Linux) go build -v -o fglps R

Hysteresis 6 Jul 23, 2022
Port of HawkAPI's cloudscraper

hawk-go Port of HawkAPI's cloudscraper Everything is exposed to give access to modification, this is subject to change. Installation: go get github.co

null 26 Nov 11, 2022
port close check scanner. detects open ports, sends alert with slack.

aite9 (port close check scanner) サーバのポートが空いてないことを確認するポートスキャナー たくさんのサーバを管理していると設定ミスで内部利用ポートが外部に公開されてしまっている可能性があり、それに早く気付くためのチェックツールです。 サーバのリストを標準入力で渡すと

Yasushi Ichikawa (ichikaway) 8 Feb 3, 2022
TCP Port Scanner in GO lang

Port-Scanner-GO Simple TCP port scanner in golang. Installation & Build You have to have GO version 1.13 run: go build port-scanner-go.go Run single

M Amin Nasiri 6 Jun 6, 2022
Port Scanner & Banner Identify From TianXiang

TXPortMap Port Scanner & Banner Identify From TianXiang ./TxPortMap -h 新增加彩色文字输出格式 对http/https协议进行title以及报文长度打印,获取title失败打印报文前20字节 新增日志文件以及扫描结果文件 T

4DOGS 461 Nov 30, 2022
A port scanner written in go

GoScanner A poor mans port scanner written in go Why? To help learn go Try and build something "somewhat" functional from the command line ?? To not s

Gobias 2 Sep 15, 2021
golang script to check server & port status

netcheck Simple script to check if host alive by sending ICMP messages & TCP Port checks. ICMP messages not working without sudo privileges. usage net

Vyacheslav Gerasimov 3 Sep 2, 2022