package main
import (
"fmt"
"os/exec"
"strings"
)
func getGroups() ([]string, error) {
var groups []string
patch := "/groups"
cmd := exec.Command("whoami", patch)
output, err := cmd.Output()
if err != nil {
return nil, err
}
lines := strings.Split(string(output), "\n")
for _, line := range lines {
if strings.HasPrefix(line, "S-1-5-21") {
groups = append(groups, line)
}
}
return groups, nil
}
func main() {
groups, err := getGroups()
if err != nil {
fmt.Printf("Ошибка получения групп пользователя: %v\n", err)
return
}
fmt.Println("Группы пользователя:", groups)
}
class ClassWithPrivate {
#privateField;
publicField;
constructor() {
this.#privateField = "Доступ только изнутри класса";
}
}
const instance = new ClassWithPrivate();
instance.publicField = "Доступ извне класса";
instance.#privateField; // Ошибка: SyntaxError: Private field '#privateField' must be declared in an enclosing class
class Animal {
constructor(name) {
this.speed = 0;
this.name = name;
}
run(speed) {
this.speed = speed;
alert(`${this.name} бежит со скоростью ${this.speed}.`);
}
stop() {
this.speed = 0;
alert(`${this.name} стоит.`);
}
}
class Rabbit extends Animal {
hide() {
alert(`${this.name} прячется!`);
}
stop() {
super.stop(); // вызываем родительский метод stop
this.hide(); // и затем hide
}
}
let rabbit = new Rabbit("Белый кролик"); // используется конструктор родителя
rabbit.run(5); // Белый кролик бежит со скоростью 5.
rabbit.stop(); // Белый кролик стоит. Белый кролик прячется!
<html>
<body onload="Load()">
<dialog></dialog>
<script>
function Load() {
setTimeout(() => {
// Создаём колбэк, функцию, которая будет вызываться только после нажатия на кнопку
const callback = function () {
alert("!");
};
Myconfirmselect(
"Готовы?" +
"¤" +
"Да" +
"¥" +
"alert('Да');" +
"º" +
"Нет" +
"¥" +
"alert('Нет');",
callback, // Передаём колбэк в функцию создания диалога
);
}, 500);
}
function Myconfirmselect(VarInput, callback) {
const dialog = document.querySelector("dialog");
dialog.innerHTML += `
<div>
<textarea></textarea>
</div>
`;
const textarea = dialog.querySelector("textarea");
const div = dialog.querySelector("div");
dialog.style.textAlign = "center";
textarea.style.width = "100%";
textarea.style.textAlign = "center";
textarea.style.resize = "none";
textarea.readOnly = true;
textarea.value = VarInput.split("¤")[0];
for (
let i = 0;
i < VarInput.split("¤")[1].split("º").length;
i++
) {
const VarButton = document.createElement("button");
VarButton.textContent = VarInput.split("¤")[1]
.split("º")
[i].split("¥")[0];
VarButton.id = VarInput.split("¤")[1]
.split("º")
[i].split("¥")[1];
VarButton.style.marginLeft = "10px";
VarButton.style.marginTop = "10px";
VarButton.addEventListener("click", () => {
eval(event.target.id);
// Вызов того самого callback после нажатия на кнопку
callback();
//ButtonClosealert();
});
div.appendChild(VarButton);
}
function ButtonClosealert() {
dialog.style.animation = "AnimFormHide 0.1s both";
setTimeout(() => {
dialog.style.textAlign = "initial";
const div = dialog.querySelector("div");
dialog.removeChild(div);
dialog.close();
}, 100);
}
dialog.style.animation = "AnimFormShow 0.25s both";
dialog.showModal();
}
</script>
<style>
@keyframes AnimFormShow {
0% {
transform: translateY(-150%);
}
}
@keyframes AnimFormHide {
100% {
transform: translateY(-150%);
display: none;
}
}
dialog,
#DialogCycle {
border: 2px solid black;
border-radius: 15px;
}
dialog div,
#DialogCycle div {
position: initial;
}
dialog::backdrop,
#DialogCycle::backdrop {
background: rgba(0, 0, 0, 0.6);
}
</style>
</body>
</html>
package app
import (
"fmt"
"io"
"log/slog"
"os"
)
// SetupLogger создаёт логгер на основании конфига
// Конфигурируем дефолтный slog и возвращаем функцию закрытия файла логов,
// если был выбран файл как место логгирования.
func SetupLogger(cfg config.Config) func() error {
closer := func() error { return nil }
level := cfg.LogLevel
var w io.Writer
switch cfg.LogOutput {
case config.LogOutputStderr:
w = os.Stderr
case config.LogOutputStdout:
w = os.Stdout
case config.LogOutputFile:
w, closer = getFileWriter(cfg)
}
var handler slog.Handler
switch cfg.LogFormat {
case config.LogFormatText:
handler = slog.Handler(slog.NewTextHandler(w, &slog.HandlerOptions{Level: level}))
case config.LogFormatJSON:
handler = slog.Handler(slog.NewJSONHandler(w, &slog.HandlerOptions{Level: level}))
}
slog.SetDefault(slog.New(handler))
return closer
}
// getFileWriter возвращает файл, куда писать логи и функцию закрытия этого файла
func getFileWriter(cfg config.Config) (*os.File, func() error) {
logDir := fmt.Sprintf("%s/%s", cfg.VarDir, cfg.LogDir)
err := os.MkdirAll(logDir, 0755)
if err != nil {
panic(fmt.Sprintf("error creating directory: %s; %v", logDir, err))
}
filename := fmt.Sprintf("%s/%s.log", logDir, cfg.AppEnv)
f, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
panic(fmt.Sprintf("error opening file: %s %v", filename, err))
}
return f, f.Close
}
package main
import "app"
func main() {
// .....
closeLogFile := app.SetupLogger(cfg)
defer closeLogFile()
// ...
}