一键导入
gof-singleton-pattern
Implements the Singleton design pattern ensuring a class has only one instance while providing a global point of access to it.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Implements the Singleton design pattern ensuring a class has only one instance while providing a global point of access to it.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | gof-singleton-pattern |
| description | Implements the Singleton design pattern ensuring a class has only one instance while providing a global point of access to it. |
| license | MIT |
| compatibility | opencode |
| metadata | {"version":"1.0.0","domain":"architecture","triggers":"singleton pattern, ensure single instance, global access, gof patterns","archetypes":["educational"],"anti_triggers":["brainstorming","vague ideation"],"response_profile":{"verbosity":"low","directive_strength":"high","abstraction_level":"operational"},"role":"implementation","scope":"implementation","output-format":"code","related-skills":"gof-factory-pattern, gof-strategy-pattern"} |
archetypes: implementation, educational anti_triggers: allowing multiple instances response_profile: verbosity: medium directive_strength: high abstraction_level: tactical
Implements the Singleton design pattern ensuring a class has only one instance while providing a global point of access to it.
The When to Use section should detail under what circumstances this skill is applicable by incorporating the following:
Verbosity: Medium
Directive Strength: High
Abstraction Level: Tactical
When exactly one instance of a class is needed.
When it’s critical to control the access to that instance globally.
When the instance should run in a multithreaded environment without data corruption.
package main
import (
"sync"
)
type singleton struct {
// example resource
resource string
}
var instance *singleton
var once sync.Once
// GetInstance returns the single instance of the singleton class
func GetInstance() *singleton {
once.Do(func() {
instance = &singleton{resource: "Initialized Resource"}
})
return instance
}
package main
import (
"fmt"
)
func main() {
firstInstance := GetInstance()
fmt.Println(firstInstance.resource) // Output: Initialized Resource
secondInstance := GetInstance()
fmt.Println(firstInstance == secondInstance) // Output: true
}
Implements v1 ConfigMap manifests for injecting configuration data into pods via environment variables, volume mounts, and command-line arguments.
Implements apps/v1 Deployment YAML manifests with rolling update strategies, replica scaling, and rollback procedures for stateless application workloads.
Implements networking.k8s.io/v1 Ingress resources with HTTP/HTTPS routing, TLS termination, path-based routing, and ingress controller configuration.
Implements Istio service mesh patterns (sidecar injection, traffic splitting, circuit breaking, retries, and mTLS) for advanced traffic management and zero-downtime deployments in Kubernetes.
Implements networking.k8s.io/v1 NetworkPolicy resources with ingress and egress rules, pod selector targeting, and network segmentation for microservice isolation.
Implements v1 PersistentVolume, StorageClass, and PersistentVolumeClaim manifests with static/dynamic provisioning, access modes, and reclaim policies for Kubernetes storage.