Giter Club home page Giter Club logo

Comments (4)

xhd2015 avatar xhd2015 commented on September 21, 2024

A possible solution is to intercept at caller side.

Or we can recognize the caller, if that is not directly from main module, we skip trapping.

from xgo.

xhd2015 avatar xhd2015 commented on September 21, 2024
func getCacheFilePath() (string, error) {
	dir, err := os.UserCacheDir()
	if err != nil {
		return "", err
	}

	cacheDir := filepath.Join(dir, "go-size-analyzer")

	err = os.MkdirAll(cacheDir, 0755)
	if err != nil {
		return "", err
	}

	file := filepath.Join(cacheDir, fmt.Sprintf("webui-v%s.html", gsa.StaticVersion))

	return file, nil
}

As for the above code, when os.UserCacheDir, os.MkdirAll and filepath.Join is called, only these directly from main module will be trapped. Or even only allowed when xgo test is being used.

Seems this strategy is fine enough to satisfy possible use cases while prevents performance or security issues.

This will be available in the next version in 3 days.(v1.0.36, 2024-05-19)

from xgo.

xhd2015 avatar xhd2015 commented on September 21, 2024

Should fail with message prompting that stdlib mocking only available in test mode when attempting patching in normal code.

from xgo.

xhd2015 avatar xhd2015 commented on September 21, 2024

It seems that these packages cannot be mocked by nature:

syscall, reflect, sync,  sync/atomic, testing, unsafe

from xgo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.